unix - ksh: grep command for multiple string. If all the strings found then only return the result -
is there way grep 2 strings in ksh , return true if both string found?
we can use egrep command if of string found. matching string , return true string present.
grep "string1" "sring2" file.txt not working.
kindly help. in advance.
edit:
please note if grep not used other option can use purpose. first string present in 1st line of file , string2 present in other line of file.
you can try
grep "string1.*string2" file in test string1 must come before string2 in same line bee true.
or can do:
grep string1 file | grep string2 this true if string1 , string2 found
using awk
awk '/string1/ && /string2/' file to search on line
awk '/string1/ {f1=1} /string2/ {f2=1} end {if (f2 && f1) print "found"}' file to exit status (cred adrian)
awk '/string1/ {f1=1} /string2/ {f2=1} end {exit !(f1 && f2)}' file this give exit status 0 of both pattern found, 1 if not
Comments
Post a Comment