Operating System - HP-UX
1748165 Members
4128 Online
108758 Solutions
New Discussion юеВ

Does awk have a 'like' operator?

 
SOLVED
Go to solution
Jamie Collins
Advisor

Does awk have a 'like' operator?

Wondering if there's a way to use a like operator in an if statement within awk..

awk '{if ($1 'like' "Joh%".....

Do I use an * wildcard or what?
3 REPLIES 3
Sridhar Bhaskarla
Honored Contributor
Solution

Re: Does awk have a 'like' operator?

Hi Jamie,

"~" is like like operator.

awk '$1 ~ /typ/ {print $1}' data

will print all $1's that has the string 'typ' in them.


-Sri

You may be disappointed if you fail, but you are doomed if you don't try
Bob Smith_23
Advisor

Re: Does awk have a 'like' operator?

also, you can use !~ to find lines that are 'not like' the string you are searching for.
Muthukumar_5
Honored Contributor

Re: Does awk have a 'like' operator?

We can do with awk's default function index too as,


awk '{ if ( index ($1,"Joh%") == 1 ) print $1 }'

Upon getting index on inputstring the Joh% will make to print $1 string there.

HTH.
Easy to suggest when don't know about the problem!