Gawk matching: Difference between revisions

From wikinotes
(Created page with "= match = <blockquote> match checks for a matching string, returns char number if found, otherwise returns a 0 <source lang="awk"> match($0, "searchterm") </source> <source...")
(No difference)

Revision as of 01:28, 19 July 2021

match

match checks for a matching string, returns char number if found, otherwise returns a 0

match($0, "searchterm")
echo "abcdefg" | awk '{var=match($0, "cd"); print var}'
#> 3

echo "abcdefg" | awk '{var=match($0, "zef"); print var}'
#> 0

echo "abcdefg" | awk '{ 
   if(match($0, "cd")) { 
       print "match found"; 
   } 
}'
#> match found