Hi All,
I have an awk command that uses the substr function - At the moment I know the length of the values so can use the example below i.e substr(i,0,1)
However in future these lengths may change so wondered if you can use a delimiter within a substr? Like in bash you could use cut -d ';', is there a similar function in awk?
awk 'BEGIN{FS=OFS=","}
NR==1{print;next}
{a[$4";"$7";"$8";"$13]+=$9}
END{for(i in a)print $1, $2, $3, substr(i,0,1), $5, $6, substr(i,3,10), substr(i,14,10), a, $10, $11, $12}' file.txt
IN the above example
i=2;2015-12-01;2016-12-01;Y1
If for example the first value (2) changed to 0002 then substr(i,0,1) would not pick up the entire value.
Thanks in advance for your help.