LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 11-24-2008, 04:44 PM   #1
nectroll
LQ Newbie
 
Registered: Nov 2008
Posts: 3

Rep: Reputation: 0
Question Need sed help or other equivalent command....


I need to extract the rusage mem= values from gibberish similar to the following:

0]rusage[DS=1:mem=5000]>;MonNov2415:33:54:[49]startedon<somecomputer@somewhere>,Executionm]rusage[mem=10000]>;TueNov1807:03:24:Startedon<somecomputer@somewhere>,ExecutionHomeces<select[linux&&mem>10000&&maxmem32G]rusage[mem=10000]span[hosts=1]>;

In the above example this would be:
5000
10000
10000

Keep in mind that this information will not always be located in the same place in the data stream, if it were I would just use awk.

The normal output of this data is not all scrunched, but I figured it might be easier to parse than something wrapped, broken, and like this:

blah blah blah blah blah rusage[me
m=123456] blah blah blah





Thank you.

Joel
 
Old 11-24-2008, 04:50 PM   #2
Poetics
Senior Member
 
Registered: Jun 2003
Location: California
Distribution: Slackware
Posts: 1,181

Rep: Reputation: 49
What have you tried so far? What does a regexp such as /mem=\d+/ find?
 
Old 11-24-2008, 05:02 PM   #3
nectroll
LQ Newbie
 
Registered: Nov 2008
Posts: 3

Original Poster
Rep: Reputation: 0
Please forgive my ignorance, but exactly how would I implement that regular expression. I am sure I could learn sed really well with enough time, but right now it still seems very cryptic.
 
Old 11-24-2008, 05:30 PM   #4
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
If test.txt contains
Quote:
0]rusage[DS=1:mem=5000]>;MonNov2415:33:54:[49]startedon<somecomputer@somewhere>,Executionm]rusage[mem=10000]>;TueNov1807:03:24:Startedon<somecomputer@somewhere>,ExecutionHomeces<select[linux&&mem>10000&&maxmem32G]rusage[mem=10000]span[hosts=1]>;
then
Code:
sed -e 's/^.*mem=\([0-9]*\).*mem=\([0-9]*\).*mem=\([0-9]*\).*/\1\n\2\n\3/' < test.txt
gives
Code:
5000
10000
10000
(I'm trying to improve my own sed'ing)
 
Old 11-24-2008, 05:38 PM   #5
nectroll
LQ Newbie
 
Registered: Nov 2008
Posts: 3

Original Poster
Rep: Reputation: 0
Thank you!!!

This works very well!!! Do you have and Sed or Regular Expression books or links you recommend?

Joel
 
Old 11-24-2008, 05:40 PM   #6
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
Try this http://www.ibm.com/developerworks/li...ry/l-sed1.html
 
Old 11-24-2008, 06:15 PM   #7
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Do you always know how many matches to expect ??. Your (latest) reply indicates the "rusage" reference in your initial post is irrelevant. Needing that as preceding data would have made things messy.
I would be inclined to use something like this
Code:
egrep -o 'mem=[[:digit:]]*' gibberrish.txt | sed 's/^mem=//'
 
Old 11-24-2008, 07:41 PM   #8
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by nectroll View Post
I am sure I could learn sed really well with enough time, but right now it still seems very cryptic.
That's because it IS cryptic......


When learning SED, start simple, eg:

sed 's/old/new/' filename ##replace all "old" with "new"

sed -n '1p' filename ##print just line 1

sed -n '1,3p' filename ##print lines 1 thru 3

sed -n '/Tom/p' filename ##print all lines containing "Tom"

Quote:
This works very well!!! Do you have and Sed or Regular Expression books or links you recommend?
http://www.grymoire.com/Unix/
 
  


Reply

Tags
sed



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
Equivalent command to rpm -qf keysorsoze Solaris / OpenSolaris 2 08-13-2007 07:51 PM
A command equivalent to c:\>dir /a/s/d AGazzaz Linux - General 2 09-06-2006 04:14 PM
Require Linux/Perl equivalent command for windows Command alix123 Programming 7 08-19-2005 02:23 AM
equivalent command in fedora pa_ash Linux - Newbie 1 06-28-2004 02:52 AM
equivalent command in fedora pa_ash Linux - Software 0 06-28-2004 01:27 AM

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

All times are GMT -5. The time now is 06:58 PM.

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
Open Source Consulting | Domain Registration