I'm parsing the IDv3 tags of mp3 files for my application and I'm using id3v2 for it. For example, to get the album name of an mp3 file the command is
id3v2 -R sample.mp3 | grep "TALB"
which outputs
TALB: Album Name
But, I want to get only the value of TALB, not the entire line so I passed it to the sed as follows
id3v2 -R sample.mp3 | grep "TALB" | sed 's/TALB: //'
which outputs
Album Name
So, here are my questions:
grep. If so, how can I do it?TCON it returns example.com (255) in which I need only the example.com. So, how can I write regex in the grep for this type?You can use Perl-style regex with the -P flag:
grep -Po '(?<=TALB: ).*'
eg:
$ echo "TALB: Album Name" | grep -Po '(?<=TALB: ).*'
Album Name
(?<=TALB: ) is a zero-width look-behind assertion. .* is the pattern for the rest of the stuff you want to match - in the first case, everything. If you want to match only specific strings after the marker string, as in your second question, then you can change this to suit your specific data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With