Jun 11, 2004 #1 Petemush Technical User Jun 21, 2002 255 GB I'm pretty sure there isn't an option on grep but can anyone think of a way to only return the first matching line that grep finds? Cheers
I'm pretty sure there isn't an option on grep but can anyone think of a way to only return the first matching line that grep finds? Cheers
Jun 11, 2004 Thread starter #2 Petemush Technical User Jun 21, 2002 255 GB I've just noticed that the option -m might be what I'm after but I don't seem to have it with my version of grep. Bugger! Upvote 0 Downvote
I've just noticed that the option -m might be what I'm after but I don't seem to have it with my version of grep. Bugger!
Jun 11, 2004 #3 PHV MIS Nov 8, 2002 53,708 FR Something like this ? grep 'pattern' /path/to/file | head -1 You may also consider this: awk '/pattern/{print;exit}' /path/to/file Hope This Helps, PH. Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244 Upvote 0 Downvote
Something like this ? grep 'pattern' /path/to/file | head -1 You may also consider this: awk '/pattern/{print;exit}' /path/to/file Hope This Helps, PH. Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
Jun 20, 2004 #4 guggach Programmer Jun 10, 2004 159 CH the fastest way ... on cmd line (note the syntax): sed -n '/pattern/{;p;q;}' filename using files, put in sed-cmd: #n /pattern/{ p q } then enter: sed -f sed-cmd filename guggach Upvote 0 Downvote
the fastest way ... on cmd line (note the syntax): sed -n '/pattern/{;p;q;}' filename using files, put in sed-cmd: #n /pattern/{ p q } then enter: sed -f sed-cmd filename guggach