i get text files with
Action & Adventure|2012: Supernova NR|2009-11-01 00:01:00|2010-05-01 23:59:00|Active|3
Action & Adventure|50 Dead Men Walking|2010-01-05 00:01:00|2010-06-30 23:59:00|Active|4
Action & Adventure|Afterwards|2009-11-26 00:01:00|2010-03-26 23:59:00|Deactivated|6
Based on the last column value of the row, i have to insert number of pipes after the 2nd column.
i know the way how to create if it is 3, 4, etc.. like.
awk -F"|" '$NF==3{{printf "%s|%s",$1,$2}{for(i=0;i<=$NF;i++){printf "|"}}{printf "%s|%s|%s|%s|\n",$3,$4,$5,$6}}' a.txt > F.txt
awk -F"|" '$NF==4{{printf "%s|%s",$1,$2}{for(i=0;i<=$NF-1;i++){printf "|"}}{printf "%s|%s|%s|%s|\n",$3,$4,$5,$6}}' b.txt >FF.txt
My problem is i can't hard code like $NF==3, $NF==4 for each value as we don't know the value that is coming in the file.
Is there a way to do it for any value in the last column?
Thanks in advance.