我正在编写一个脚本,用于显示学校mp3文件上的id3标签信息。我已经能够获得最后一行,但在获取元数据时遇到了问题。
元数据以字符串标签开头。我的脚本获取该字符串的位置,然后尝试提取从该位置开始的行。
输出的是元数据开始之前的最后一行。
我已经更改了数字,但输出没有变化,只有一个例外。File1当我有意地从Pos76中提取小于匹配的字符时,我会像我所期望的那样得到更多的字符。
脚本
for f in *.mp3
do
echo;
echo;
echo the last line of the file is;
lastLine=`tail -1 $f`
echo $lastLine;
echo;
pos=`expr index "$lastLine" TAG`;
echo match is found at pos $pos;
echo getting the string starting at pos 122;
echo ${lastLine:122}
echo;
echo getting the string starting at pos 150;
echo ${lastLine:150}
echo;
echo getting the string starting at pos 76;
echo ${lastLine:76}
echo;
done2个不同mp3文件的输出


发布于 2012-03-13 16:01:37
使用shell脚本解析二进制数据是非常有用的,特别是在实际编码未定义的情况下,例如使用ID3标记。正如php-coder所建议的,您可能想要使用一个工具来为您做处理。
发布于 2012-03-13 16:13:09
您可以通过echo访问strings来去除那些无法打印的字符
$ echo -e '\x87hello\x99' | strings
hello发布于 2012-03-13 16:15:20
你最好使用这样的东西:
#!/bin/bash
for f; do
echo -e "\n\n\nthe last line of the file is"
lastLine=$(strings $f | tail -1)
echo $lastLine
echo
pos=$(expr index "$lastLine" TAG)
cat<<EOF
match is found at pos $pos
getting the string starting at pos 122
${lastLine:122}
getting the string starting at pos 150
${lastLine:150}
getting the string starting at pos 76
${lastLine:76}
EOF
done然后
./script *mp3
使用strings的请参阅man 1 strings
https://stackoverflow.com/questions/9680159
复制相似问题