Displaying only data matching a pattern?

Alan Johnson alan at datdec.com
Mon Feb 2 11:46:22 EST 2009


Your man-fu might be a bit off too. ;)  From the grep man page:
       -o, --only-matching
              Print  only  the  matched  (non-empty) parts of a matching
line,
              with each such part on a separate output line.

Also, if you have cut, it will probably run faster with:

cut -d ':' -f 2 $file | cut -d '\' -f 1
or
<your output> | cut -d ':' -f 2 | cut -d '\' -f 1

No regex generally means faster run times.

Enjoy!

On Mon, Feb 2, 2009 at 11:19 AM, kenta <kenta at guster.net> wrote:

> I've been working with some large files and need to extract a piece of
> info, unfortunately there's a bunch of junk around the part that I
> want.  Example:
> foofoo:A1234567890B\barbar
> foofoo:C9234567890E\barbar
> foofoo:A8234567890B\barbar
> foofoo:F7234567890D\barbar
>
> What I had done the first pass to get what I wanted was to use sed and
> do a  s/foofoo:// to get rid of the stuff in front, and then do the
> same for the \barbar in the back.  However what would be easier for me
> is if I could just extract the pattern of [a-fA-F0-9] when they appear
> n times in a row. I couldn't seem to figure out if sed could display
> only the part I wanted.  So I figured it'd be a better job for grep,
> however It appears that it's printing the entire matching line and I
> only want the match on the pattern to display.
>
> Otherwise, I want as an end result:
>
> A1234567890B
> C9234567890E
> A8234567890B
> F7234567890D
>
> Here's a caveat: I need to do this on a Windows box and am limited to
> using the ports of  GNU utilities (using
> http://unxutils.sourceforge.net/) otherwise I'd do this in perl and
> wouldn't be asking :/   I'm thinking maybe I'm just missing something
> simple here.
>
> Any quick solutions?  My Google-fu is weak today.
>
> -Kenta
> _______________________________________________
> gnhlug-discuss mailing list
> gnhlug-discuss at mail.gnhlug.org
> http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/
>



-- 
Alan Johnson
alan at datdec.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.gnhlug.org/mailman/private/gnhlug-discuss/attachments/20090202/d3e478c0/attachment.html 


More information about the gnhlug-discuss mailing list