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! |
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 |
Thanks for the response. I tried it, but still have the complete file as output.
? |
How about this...
sed -n "s/\(.*\)\(size\=[0-9]*\)\(.*\)/\2/p" file.txt |
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 |
Thanks! that works great!
|
All times are GMT -5. The time now is 08:11 AM. |