sed syntax

Jamon Camisso jamon.camisso-H217xnMUJC0sA/PxXw9srA at public.gmane.org
Tue Feb 3 19:29:43 UTC 2009


Lennart Sorensen wrote:
> On Tue, Feb 03, 2009 at 11:20:44AM -0500, Matt Price wrote:
>> after all these years with linux i still have all kinds of trouble with
>> regexp's.  i have a file full of error messages from dmesg:
>>
>> [125559.165041] Buffer I/O error on device sda5, logical block 19698429
>>
>> (i know, it's not a good sign; i'm just trying to hang onto this drive
>> for a little longer)
>>
>> i want to cut these lines back so i just have the block number:
>> 19698429
>>
>> now, i know i can do that with 'cut -d " " -f 10', but my first impulse
>> was to do it with sed, and i, as usual, don't understand what i'md doing
>> wrong.  since i just want the final 8-digit block number, i thought i
>> could do this:
>> cat file | sed 's/(^.*)([0-9]*$)/\2/' 
>>
>> but that returns the initial file unmodified.  
>>
>> any ints out there?  thanks as always,
> 
> How about:
> 
> sed 's/.*block \([0-9]*\)$/\1/'
> 
> I think the main problem was you failed to escape the ()'s which sed
> requires.
> 

Sed works, but awk is designed for just the task you're attempting:
cat file.txt | awk '{print $10}'

Jamon
--
The Toronto Linux Users Group.      Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists





More information about the Legacy mailing list