LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   sed parsing question (https://www.linuxquestions.org/questions/linux-newbie-8/sed-parsing-question-271967/)

ncblues 12-30-2004 12:39 PM

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!

zulfilee 12-30-2004 12:56 PM

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

ncblues 12-30-2004 01:13 PM

Thanks for the response. I tried it, but still have the complete file as output.
?

homey 12-30-2004 01:27 PM

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

zulfilee 12-30-2004 11:58 PM

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

ncblues 01-03-2005 06:36 AM

Thanks! that works great!


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