Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] pattern matching



>>>>> "Brett" == Brett Robson <b-robson@example.com> writes:

    Brett> I want to grep for a pattern but I don't want to see the
    Brett> whole line, just the bit that matches. Sometimes I pipe to
    Brett> cut but in this case I don't know where the pattern will
    Brett> be. Surely this is straight forward?

grep -e 'PATTERN' | sed -e 's/.*\(PATTERN\).*/\1/'
perl -ane 'print "$&\n" if /PATTERN/'

There must be a way of doing this using awk, but I can't remember it.


-- 
Institute of Policy and Planning Sciences     http://turnbull.sk.tsukuba.ac.jp
University of Tsukuba                    Tennodai 1-1-1 Tsukuba 305-8573 JAPAN
               Ask not how you can "do" free software business;
              ask what your business can "do for" free software.


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links