LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-16-2008, 09:34 AM   #1
pslacerda
Member
 
Registered: Nov 2008
Posts: 42

Rep: Reputation: 17
Question Format output


When list id3 tags with id3v2 command this is the output:

Code:
id3v1 tag info for /home/música/Black Alien/Black Alien - Como eu te quero.mp3:
Title  : Como eu te quero                Artist: Black Alien                   
Album  :                                 Year:     , Genre: Rap (15)
Comment:                                 Track: 5
I want format to something like:

Code:
/home/música/Black Alien/Black Alien - Como eu te quero.mp3 | Como eu te quero | Black Alien | Rap
How do it?

Help me!
 
Old 12-16-2008, 09:47 AM   #2
Agrouf
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: LFS
Posts: 1,591

Rep: Reputation: 79
You can do it with sed and cut.
type:
man sed
man cut
 
Old 12-16-2008, 10:28 AM   #3
pslacerda
Member
 
Registered: Nov 2008
Posts: 42

Original Poster
Rep: Reputation: 17
I can use cut, but sed is greek for me. And I don't understand how combine this tools and get my resolution Can you light me? I'm VERY newbie.
 
Old 12-16-2008, 11:33 AM   #4
pslacerda
Member
 
Registered: Nov 2008
Posts: 42

Original Poster
Rep: Reputation: 17
Sed adresses are lines, id3v2 -l output are organized by spaces. And cut work with delimeters, but the output don't have a simple delimeter, like dots or tabs; are spaces that may vary, 1 or 16.

You can see how do it, but i'm yet blind in linux. Help me, please.
 
Old 12-16-2008, 01:35 PM   #5
Agrouf
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: LFS
Posts: 1,591

Rep: Reputation: 79
The output does have delimeters. fields are separated from their title with colons and sed can replace spaces with colons.
try this:
Code:
id3v2 -l | sed -e :a -e 's/tag info for /:/g' -e 's/   */:/g' -e N -e 's/\n/:/' -e ta | cut -f2,6,8,16 -d: --output-delimiter=" |"

Last edited by Agrouf; 12-16-2008 at 01:39 PM.
 
Old 12-16-2008, 01:54 PM   #6
pslacerda
Member
 
Registered: Nov 2008
Posts: 42

Original Poster
Rep: Reputation: 17
Thank you, fast and precise!

If want... can you explain it?
 
Old 12-17-2008, 04:10 AM   #7
Agrouf
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: LFS
Posts: 1,591

Rep: Reputation: 79
The idea is to make a long line out of the 3 lines with fields separated by colons ( and to cut the interesting fields

sed commands:
to replace a string by another:
s/replacestr/tostr/g
To append next line to the buffer:
N
to create a label:
:label
to jump to a label if previous command was successful:
tlabel
to get more informations on sed commands:
man sed

First, we put a label to jump to later on (we call the label "a": -e :a
Next, we replace "tag info for" with a colon ":" so as to isolate the actual information in a field: s/tag info for /:/g
Next, we replace long sequences of spaces with a colon to separate fields: 's/ */:/g'
Next, wa append the next line to the buffer: -e N
Next, we replace the new line with a colon to separate lines: -e 's/\n/:/'
Finally, we jump to the label we created earlire in order to process other lines (if there are): -e ta

Now we have a line with many fields separated by colons. We just have to extract the interesting ones with cut:
cut -f2,6,8,16 -d: --output-delimiter=" |"
 
Old 12-17-2008, 12:26 PM   #8
pslacerda
Member
 
Registered: Nov 2008
Posts: 42

Original Poster
Rep: Reputation: 17
Why need we put a label on start of the line and call it on every end? What labels does? I learned that sed read line by line. Or one an other nothing to do?

I bothering you, right?
thanks

Last edited by pslacerda; 12-17-2008 at 12:28 PM.
 
Old 12-17-2008, 01:33 PM   #9
Agrouf
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: LFS
Posts: 1,591

Rep: Reputation: 79
No you're not (bothering me). My answers look rude because I'm quitting smoking. Nothing to do with you.
the N command appends the next line to the current buffer, so sed can prosess multiple lines at one time. We need to call the label again because there are more than 2 lines, so the third and fourth line are appended on the second and third pass.
 
Old 12-20-2008, 12:38 PM   #10
pslacerda
Member
 
Registered: Nov 2008
Posts: 42

Original Poster
Rep: Reputation: 17
Come backing,

How to apply this commands on a lot of files? I learned in this forum that
Code:
find /directory -exec id3v2 -l '{}' \;
do it. But when I pipe to sed format occurs an ugly problem.

After formated, the options | sed -e :a -e N -e ta | join all lines in one. Something like this:

Code:
id3v1:/home/música/Marcelinho da Lua; Seu Jorge/Marcelinho da Lua; Seu Jorge - Cotidiano.mp3::Title:: Cotidiano:Artist: Marcelinho da Lua; Seu Jorge::Album:::Year::, Genre: Drum & Bass (127):Comment::Track: 0:id3v2:/home/música/Marcelinho da Lua; Seu Jorge/Marcelinho da Lua; Seu Jorge - Cotidiano.mp3::TIT2 (Title/songname/content description): Cotidiano:TPE1 (Lead performer(s)/Soloist(s)): Marcelinho da Lua; Seu Jorge:TCON (Content type): Drum & Bass (127):id3v1:/home/música/John Lennon/John Lennon - Stand by me.mp3::Title:: Stand by me:Artist: John Lennon::Album:::Year::, Genre: Blues (0):Comment::Track: 1:id3v1:/home/música/John Lennon/John Lennon - Watching the Wheels.mp3::Title:: Watching the Wheels:Artist: John Lennon::Album:::Year::, Genre: Rock (17):Comment::Track: 0
So the | cut -d":" -f2,6,8,16 | cat only the fields from the first music, because the others musics are on the same line. For cut works well here each music need be on your own line.

Can somebody solve me this new one?

Last edited by pslacerda; 12-20-2008 at 12:45 PM. Reason: syntax erros
 
Old 12-20-2008, 02:19 PM   #11
Agrouf
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: LFS
Posts: 1,591

Rep: Reputation: 79
I see your problem.
You need to execute the sed command inside the -exec, not after the find, so the lines are appended at each call to id3v2 and not everytime.
I believe the easiest way to do it is to create a command that does the id3v2 | sed | cut
like that:
Code:
echo "id3v2 -l \"\$1\" | sed -e :a -e 's/tag info for /:/g' -e 's/   */:/g' -e N -e 's/\n/:/' -e ta | cut -f2,6,8,16 -d: --output-delimiter=\" |\"" >/tmp/mycommand.sh
chmod a+x /tmp/mycommans.sh
Then you can execute command in the -exec of the find like that:
Code:
find /directory -exec /tmp/mycommand.sh '{}' \;
 
Old 12-21-2008, 09:56 AM   #12
pslacerda
Member
 
Registered: Nov 2008
Posts: 42

Original Poster
Rep: Reputation: 17
Thumbs up

Thanks again
You won't be forgotten, for me Linux start here

last, I promise: what difference between sed 's/old/new/g' and 's/old/new/'
 
Old 12-21-2008, 10:01 AM   #13
Agrouf
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: LFS
Posts: 1,591

Rep: Reputation: 79
No problem, you can ask as many questions as you want, it's a pleasure to help.
the 'g' says to replace all occurrences of old with new. If you don't put a 'g', it only replaces the first occurrence of old it encounters.
try this:
Code:
echo 'xxxxx' | sed "s/x/y/"
and this:
Code:
echo 'xxxxx' | sed "s/x/y/g"

Last edited by Agrouf; 12-21-2008 at 10:03 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How can i get the ls command to output in the following format deathalele Programming 3 11-16-2008 03:07 PM
output format ust Linux - Newbie 2 09-11-2008 02:14 AM
change output format for df baddah Programming 3 04-21-2008 09:08 AM
Format bash output ceashton Programming 3 08-17-2007 01:16 PM
last command output format bujecas Linux - General 1 10-12-2006 10:54 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:34 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration