1

Trying get awk to look into a file and check if a column has a value.

  • If it has a value of "x" then print "x" into an email (via "| mail -s ").
  • If it does not match "x" then print "no value" but still send mail.

Trying something along the lines of:-

awk -F ''{if($3 != 0) {a = ($3); print $0, a;} else if ($3==0) print "No updates"}'  file.in | mail...etc 
  • What can the input look like? – Kusalananda Apr 9 '18 at 12:54
5
awk '$3 == "x" { print $3 } $3 != "x" { print "no value" }' file.in | mail ...

or

awk '{ print ($3 == "x" ? $3 : "no value") }' file.in | mail ...

or

awk '$3 != "x" { $3 = "no value" } { print $3 }' file.in | mail ...

Given the file

1 2 3
2 3 x
4 5 x

the three awk programs will produce the output

no value
x
x
1

try

awk '{ print ($3!="x")?"No Updates":$3 }' infile | mail ... 
-1

I tried by below method

g=`awk '{print NF}' l.txt| sort -nr | head -1`

For x pattern exsists

for ((l=1;l<=$g;l++)); do awk -v l="$l" '$l == "x" {print "exists in"l"column"}' l.txt| sort -u; done |mail ..

for x pattern doesnt exists

for ((l=1;l<=$g;l++)); do awk -v l="$l" '$l != "x" {print " doesnt exists in"l"column"}' l.txt|sort -u; done| mail

input file

[root@praveen_2 ~]# cat l.txt
10 x x
10 x x

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.