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 edit summary |
||
Line 1: | Line 1: | ||
= regex = | |||
<blockquote> | |||
Used to filter lines, like grep. | |||
<syntaxhighlight lang="bash"> | |||
echo ' | |||
1920x1080 | |||
foo | |||
5760x1080 | |||
' | awk '$0 ~ /[0-9]+x[0-9]+/ { print $0 }' | |||
</syntaxhighlight> | |||
</blockquote><!-- regex --> | |||
= match = | = match = | ||
<blockquote> | <blockquote> |
Revision as of 01:58, 19 July 2021
regex
Used to filter lines, like grep.
echo ' 1920x1080 foo 5760x1080 ' | awk '$0 ~ /[0-9]+x[0-9]+/ { print $0 }'
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