sed syntax

Alex Beamish talexb-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org
Tue Feb 3 21:47:10 UTC 2009


There's a simple solution with Perl:

foo at bar$ perl -ne '@w=split;print"$w[-1]\n"' <logfile >block.lst

You can use awk as well:

foo at bar$ awk '{print $NF}' <logfile >block.lst

Alex

On Tue, Feb 3, 2009 at 11:20 AM, Matt Price <matt.price-H217xnMUJC0sA/PxXw9srA at public.gmane.org> wrote:
> ok
>
> 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,
>
> matt
>
>
> --
> Matt Price
> matt.price-H217xnMUJC0sA/PxXw9srA at public.gmane.org
> --
> 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
>



-- 
Alex Beamish
Toronto, Ontario
aka talexb
--
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