-   Programming (
-   -   Just need a 'push' with sed (

MarcQuadra 09-03-2004 12:08 AM

Just need a 'push' with sed

I've been running Linux for about six years, but only now have the need to do string-manipulation for a project, before I was just doing network services and stuff.

My problem is that I'm a bonehead with 'sed'. All I want to do is remove everything from the output of a line before the divider. I already know where to put sed in this command, and this is simplified, but the OUTPUT is what I need to modify.

#for mp3 in ./*/*/*.mp3 ; do openssl dgst -sha1 "$mp3" ; done

SHA1(./Philip Glass/Powaqqatsi/Anthem - Part 2.mp3)= a686a5a167efa758c404a3a3283975406daf7486
SHA1(./Philip Glass/Powaqqatsi/Anthem - Part 3.mp3)= 7f3b426bb0db39b3aac78f738e2f355086428b86
SHA1(./Philip Glass/Powaqqatsi/Mosque And Temple.mp3)= d3da57bcc03bd3bb4b68e2473e0adababa570d6b

So, what I want to do is get ONLY the hashes of the files. I need to remove (in my own head's language) '*=\ '.

The problem is that I can't figure out how to tell sed to stop filtering characters when it hits the '= ', and I have a nagging suspicion that there's a better way, by issuing a command to remove everything before '= ', but I don't know how.

This was originally part of a script on Mac OS X that I wrote, and on OS X the 'md5 -q' command outputs ONLY the hash, so it was easy. Now I'm trying to make it work here at home on linux (for testing) and I don't have that command.

Dark_Helmet 09-03-2004 12:29 AM

Here are two ways:

The cut command (I use it more often than I should):

for mp3 in ./*/*/*.mp3 ; do openssl dgst -sha1 "$mp3" ; done | cut -f 2 -d '='
With the sed command:

for mp3 in ./*/*/*.mp3 ; do openssl dgst -sha1 "$mp3" ; done | sed "s%^[^=]*=\(.\+\)%\1%"

MarcQuadra 09-03-2004 12:59 AM

Wow! thanks!

All I had to do after that was to kill the leading space, so the grand-total is:

for mp3 in ./*/*/*.mp3 ; do openssl dgst -sha1 "$mp3" | cut -f 2 -d '=' | sed -e s/\ // ; done

Many thanks for your help, this is gonna make my project VERY easy to handle! (there's over 22,000 jazz songs that need checksums here!

All times are GMT -5. The time now is 05:06 AM.