Strange awk substr bug
am 24.01.2008 15:35:38 von vburiticaI think I may have found a bug in awk (see the same behavior in gawk
and nawk), I wanted parse a string and split the date into dashes and
still send certain other fields
info='20071231; 23:56:49; 23:56:49; 0x5be784; 1; 0x210a61; 72089944'
If I do this:
echo $info | \
awk -F'; ' '{print substr($1,1,4) "-" substr($1,5,6) "-"
substr($1,7,9) " " $2 "," $4 "," $6 "," $7}'
I get:
2007-1231-31 23:56:49,0x5be784,0x210a61,72089944
it's odd because I would expect the second substr call to behave like
the first and third, but it's printing out two extra characters. I
wanted 2007-12-31, but it's printing 2007-1231-31 instead.
I fixed this by piping it to cut, but seems pretty ugly to have to do
so.
I'm using ubuntu, just wondering if other *nix are seeing the same