LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-02-2004, 11:08 PM   #1
MarcQuadra
LQ Newbie
 
Registered: Sep 2004
Location: Randolph, MA
Distribution: Gentoo/Linux and Gentoo/OS X
Posts: 2

Rep: Reputation: 0
Just need a 'push' with sed


Greetings!

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.
 
Old 09-02-2004, 11:29 PM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 368Reputation: 368Reputation: 368Reputation: 368
Here are two ways:

The cut command (I use it more often than I should):
Code:
for mp3 in ./*/*/*.mp3 ; do openssl dgst -sha1 "$mp3" ; done | cut -f 2 -d '='
With the sed command:
Code:
for mp3 in ./*/*/*.mp3 ; do openssl dgst -sha1 "$mp3" ; done | sed "s%^[^=]*=\(.\+\)%\1%"
 
Old 09-02-2004, 11:59 PM   #3
MarcQuadra
LQ Newbie
 
Registered: Sep 2004
Location: Randolph, MA
Distribution: Gentoo/Linux and Gentoo/OS X
Posts: 2

Original Poster
Rep: Reputation: 0
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!
 
  


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
anybody have ussp-push-0.2.tgz?? maginotjr Linux - Networking 1 07-12-2005 03:32 PM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM
backup: push or pull? nielchiano Linux - General 3 02-05-2004 05:46 AM
Push installation balpeck Linux - Networking 1 09-21-2003 09:30 AM
Left_ctrl-push-button??>? matt3333 Slackware 7 12-15-2002 09:45 PM


All times are GMT -5. The time now is 01:30 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration