#!/usr/bin/gawk -f # /* vim: set filetype=gawk : */ -*- awk -*- BEGIN{ FS = ","; Fname="test"; Src = 3; Out=""; } { temp = $NF; $NF = $Src; $Src = temp; gsub(/ +/,","); gsub(/\t+/,","); Out= Out $0 "\n"; } END{ print Out>Fname; }