I receive files with lines representing datasets. Each line contains characters representing several fields of data without breaks and I need to break the lines to extract each data field eg
ABCD075BCD156300544E0001000900125349544520494
->
ABCD 075BCD 15630 0544 E00010009 00 12 5349544520494
I know the number of characters in each field, so I can do this in awk using FIELDWIDTHS. This works fine when all the datasets are the same, but they aren't. To make it more complicated, I can only tell which type of dataset it is by reading one of the fields.
So I think I need to apply a set of FIELDWIDTHS to read the data type. Then apply a different set of FIELDWIDTHS and reread the same line using getline to extract the data. But this doesn't work because the changed fieldwidths are never applied.
BEGIN {
FIELDWIDTHS = "30 2"; # set FIELDWIDTHS to read data type
}
{
print $2; # print data type
FIELDWIDTHS = "5 5 5 5 5 5 5 5 5 5 5"; # change fieldwidths to read data
getline NF; # reread current line to use new fieldwidths
print $2; # print data field
FIELDWIDTHS = "30 2"; # change fieldwidths to read next line
}
END {
}
Any advice would be appreciated.