Displaying only data matching a pattern?
    Ben Scott 
    dragonhawk at gmail.com
       
    Mon Feb  2 11:45:13 EST 2009
    
    
  
On Mon, Feb 2, 2009 at 11:19 AM, kenta <kenta at guster.net> wrote:
> extract the pattern of [a-fA-F0-9] when they
> appear n times in a row.
>
> foofoo:A1234567890B\barbar
> A1234567890B
  I *think* this will do what you want:
	
	sed s/.*:\([[:xdigit:]]*\)\\.*/\1/
  By grouping something within parenthesis, you can backreference it
in the replacement string.  By grouping the part you're interested,
but then having an ungrouped match for everything else, you can
replace each line with just the part you're interested in.
  [[:xdigit:]] matches any hex digit; a little clearer than the literal pattern.
  The literal backslash has to be escaped, contributing to leaning
toothpick syndrome.  Perl's better at this (and also available for
'doze), but you specified using only the unxutils package.
  There might be a way to do this with awk, but my knowledge of awk is
mostly limited to using it to print columns.  :)
-- Ben
    
    
More information about the gnhlug-discuss
mailing list