I have a generated csv that has the following format:
unixtime;host_name;ip_adress;description;2;0;1
I have been trying to parse this csv to do the following:
change field 1 from unix timestamp to human readable.
change field 5 from 2 to Critical
change field 6 and 7 like this:
if the value is 0 replace by NO, if it is 1 replace by yes
I have managed to do the first 2 using this:
cat test.csv |
/opt/csw/bin/gawk -F";" '{OFS=";"; $1=strftime("%Y-%m-%d %H:%M:%S", $1); print $0}' |
/opt/csw/bin/gawk -F";" '{OFS=";"; gsub("2", "CRITICAL", $5)}1'
but how do I to change the 1 by yes and the 0 by no in the fields $6 and $7?
If I try something like this it replaces everywhere it find a 0:
gawk 'BEGIN {OFS=FS=";"} {if ($6== "0") gsub ($6,"NO"); print }' sample.csv
For the record, I am using Solaris and installed gawk from opencsw.
gsub ($6,"NO")
to$6="NO"
.