String matching: Difference between revisions
Content added Content deleted
(awk cannot use ~ unless sanitized string, use index instead) |
|||
Line 998: | Line 998: | ||
<lang AWK>#!/usr/bin/awk -f |
<lang AWK>#!/usr/bin/awk -f |
||
{ |
{ |
||
⚫ | |||
if ($1 ~ "^"$2) { |
|||
⚫ | |||
print $1" begins with "$2; |
|||
print $1 " " ( substr($2,index($2,$1))==$1 ? "ends" : "does not end") " with " $2 |
|||
} else { |
|||
⚫ | |||
} |
|||
if ($1 ~ $2) { |
|||
print $1" contains "$2; |
|||
} else { |
|||
⚫ | |||
} |
|||
if ($1 ~ $2"$") { |
|||
print $1" ends with "$2; |
|||
} else { |
|||
print $1" does not end with "$2; |
|||
} |
|||
} |
} |
||
</lang> |
</lang> |