Basic conditional Awk one-liner
11,059
Solution 1
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
Solution 2
try
awk '{ print ($3!="x")?"No Updates":$3 }' infile | mail ...
Related videos on Youtube
Author by
Bee Min
Boulderer & keen sysadmin. I like computery stuff. If it has an I/O system, I wanna know. I have much to learn.
Updated on September 18, 2022Comments
-
Bee Min over 1 year
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
-
Kusalananda about 6 yearsWhat can the input look like?
- If it has a value of "x" then print "x" into an email (via