On Tue, 19 Jun 2018, Robert Citek wrote:

Couple of typos and an addition (-F,) :

  I'm not seeing the typos.

{ cat <<eof
2012-10-01,14:00,90.7999
2012-10-01,15:00,90.8121
2012-10-01,16:00,90.8121
2012-10-01,16:00,90.8121
2012-10-01,18:00,90.8091
2012-10-01,19:00,90.8030
eof
} | awk -F,  '
$2 != "16:00" { print ; next }
flag == 0 && $2 == "16:00" { print ; flag=1 ; next }
flag == 1 && $2 == "16:00" { $2="17:00"; print; flag=0 ; next }
'

  I have the code in a file and run it with the '-f' option:
gawk -f correct-double-hour.awk test.dat > out.dat

correct-double-hour.awk:

#!/usr/bin/gawk
#
# This script replaces the second instance of 16:00 with 17:00.

BEGIN { FS=","; OFS="," }
$2 != "16.00" { print ; next }
flag == 0 && $2 == "16:00" { print ; flag=1 ; next }
flag == 1 && $2 == "16:00" { $2=="17:00"; print; flag=0 ; next }

Thanks,

Rich
_______________________________________________
PLUG mailing list
PLUG@pdxlinux.org
http://lists.pdxlinux.org/mailman/listinfo/plug

Reply via email to