I've got a file which I am reading line by line (using read line) into a variable.
I then want to do a grep on that line to check for something. I've tried a number of methods none of which seem to work.
I thought I had it with the code below but for some reason it doesn't like it and comes up with the message below that
echo $line | awk 'match($line, Ashok) > 0 { echo "line matched" }'
awk: syntax error near line 1> awk: bailing out near line 1
Any ideas ? How else could I do it ?
/bin/sh
while read line ; do if echo "$line" | grep "Ashok" ; then echo "line matched" ; fi ; done
Thank you very much - that has worked a treat... ( :
wouldn't this be somewhat the same ( if not , almost ) as
# grep -q "Ashok" file && echo "line matched"
line matched
ghostdog74:
wouldn't this be somewhat the same ( if not , almost ) as
# grep -q "Ashok" file && echo "line matched"
line matched
Doh! An excellent point! :o I got wrapped up in the 'read line by line' bit and lost sight of the actual goal
BTW, The -q flag is new to me actually, one less pipe is always a good thing. Cheers!