Go with soneteer's solution. But for further background, the following will apply to other files which have a mixture of ASCII characters and binary data. (I didn't know about ogginfo, and typed the following before I saw his response.)
ogg files contain not only printable ASCII characters, but also binary data.
grep usually works with printable ASCII data, line by line. With binary data, there is no such thing as a "line" in the ASCII sense, and what would be the line termination character (LF) in ASCII data can appear anywhere in plain binary data, and that byte means whatever the binary usage would dictate.
So
grep goes out of its way to detect a binary file, and just let you know whether the specified string is within that file.
You have two ways to fix this: the wrong way, and the right way.
The wrong way, with which you may wish to experiment if you have nothing better to do, is this:
Code:
grep -a 'album=' *ogg
That will ignore the possibility that the file might contain binary data (which is the case with ogg files). What you really want to do, though, is consider just the ASCII parts of each file. You can pipe each file through the
strings command, and send the output through
grep. Try this:
Code:
for xxx in *ogg
do
strings $xxx | grep 'album=' | sed -e "s/^/$xxx:/"
done
Note that the first occurrence of
xxx is not preceded by a dollar sign. Also notice the double quotes around the
sed parameter; using single quotes would prevent the
$xxx from being interpreted properly. With double quotes, the
$xxx will get changed into the name of the individual ogg file; with single quotes, it will remain
$xxx, and that's what you'll see at the beginning of each line of output.
For more information:
Code:
man grep
man strings
man sed
Hope this helps.