LinuxQuestions.org
Help answer threads with 0 replies.
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-30-2004, 01:39 PM   #1
ncblues
LQ Newbie
 
Registered: Dec 2004
Posts: 5

Rep: Reputation: 0
sed parsing question


Hi, I'm a fairly new guy, especially using sed. I want to look in a log for all occurances of "size=xxxx," and print out those values to a new file. I've made a few feeble attempts, but cannot seem to grasp how do only get the string I'm looking for and put it into another file.

Any help would be greatly appreciated & Happy New Year!
 
Old 12-30-2004, 01:56 PM   #2
zulfilee
Member
 
Registered: Apr 2004
Location: India
Distribution: Redhat,Fedora
Posts: 430

Rep: Reputation: 39
Ex:
size=1000 Hai this is
size=4000 Second line

And you want only size=<digits>

sed -n "s/\(size\=[0-9][0-9][0-9][0-9]\)/\1/p" filename

The -n and p option are to print only what is matched

And The value between \( \) gets displayed as we specify it using \1
Ex: sed "s/\(pattern\)/\1/" file
Only prints that pattern in that line

Much better regex is possible though i have sited one possible way

Cheers
Z
 
Old 12-30-2004, 02:13 PM   #3
ncblues
LQ Newbie
 
Registered: Dec 2004
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks for the response. I tried it, but still have the complete file as output.
?
 
Old 12-30-2004, 02:27 PM   #4
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
How about this...
sed -n "s/\(.*\)\(size\=[0-9]*\)\(.*\)/\2/p" file.txt
 
Old 12-31-2004, 12:58 AM   #5
zulfilee
Member
 
Registered: Apr 2004
Location: India
Distribution: Redhat,Fedora
Posts: 430

Rep: Reputation: 39
How about this...
sed -n "s/\(.*\)\(size\=[0-9]*\)\(.*\)/\2/p" file.txt


Thanks for that Homey


The starting and ending part of the line has to be masked out

SO a '.*' at start and end is needed

sed -n "s/.*\(size\=[0-9]*\).*/\1/p" file.txt

This will also work.



Cheers
Z
 
Old 01-03-2005, 07:36 AM   #6
ncblues
LQ Newbie
 
Registered: Dec 2004
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks! that works great!
 
  


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
question on sed tifu Linux - Newbie 3 03-18-2005 05:38 PM
Text parsing question bruoersolitario Linux - General 4 04-15-2004 03:12 PM
sed question dolvmin Linux - Software 4 03-09-2004 10:27 AM
sed question zoomzoom Linux - Software 2 10-20-2003 05:04 PM
sed question 360 Programming 2 03-15-2002 10:52 AM

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

All times are GMT -5. The time now is 10:04 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