Using like operator in awk if condition

Hello All,

I have developed a script which selects a particular filed from a file ,trims it,searches for a particular pattern and then mail it when found.

cat test_file.txt |sed -n '5,$p'|sed -e 's/ //g'|awk -F'|' '{if ($4 !="Alive") print $1,$2,$3,$4}' >> proc_not_alive.txt

It is working fine,Now my requirment is to filter the processnames which begin with essbase% or has string essbase in it.I have tried the below command and it is working but I know its not the proper way to do it :slight_smile:

cat test_file.txt |sed -n '5,$p'|sed -e 's/ //g'|awk -F'|' '{if ($4 !="Alive" && $2 != "Essbase" && $2 != "EssbaseStudio") print $1,$2,$3,$4}'

So my doubt is ,I want to use something like $2 NOT like ('%Essbase%') which we do in sql query that should select processes which does not have a process name with a "Essbase" in it.Can you please help me with this.

Not supplying input not desired output samples unnecessarily complicates understanding of your problem and may result in non-working proposals as adequate test cases are missing. Plus: not describing the error (or misbehaviour) doesn't help either as it opens up a wide field for guesswork. So - help us helping you and provide samples!

Would

awk -F'|' '$4 !="Alive" && $2 !~ /^[%]*[Ee]ssbase/ {print $1,$2,$3,$4}' test_file.txt

come close to what you need?

Scrutinizing your post#1 again (again - no samples impede understanding!), I think

awk -F'|' '$4 !="Alive" && $2 !~ /[Ee]ssbase/ {print $1,$2,$3,$4}' test_file.txt

should do ...

Sorry for the inconvienece RudiC.I will take care of it in future.Both the solutions provided by you is working fine ...Thanks a lot for the help!:b::b: