Mailing List Archive


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

Re: [tlug] pattern matching



for awk

    Pattern="$1"; shift
    awk '{
     if ( match ($0, /'"$Pattern"'/) ) {
  print substr ($0, RSTART, RLENGTH)
     }
}
    ' "$@"

isn't google great :P

 "Stephen J. Turnbull" wrote:

>>>>> "Brett" == Brett Robson 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.

--
TLUG server is hosted by Open Source Development Lab Japan
http://www.osdl.jp/

To unsubscribe from this mailing list,
please see the instructions at



Do You Yahoo!?
http://bb.yahoo.co.jp/
Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links