Your loop should go from i = 2 to i = 4. Not from i = 1 to i = 3.
But there are more elegant solutions. I like this one:tr ';|' ' \n' < inputfile | awk '{ if (NR % 4 == 1) printf $0; else { if (NR % 4 == 0) print " " $2; else printf " " $2 } }'
Your loop should go from i = 2 to i = 4. Not from i = 1 to i = 3.
But there are more elegant solutions. I like this one:tr ';|' ' \n' < inputfile | awk '{ if (NR % 4 == 1) printf $0; else { if (NR % 4 == 0) print " " $2; else printf " " $2 } }'