I am trying to remove duplicates on keys in a file and so far the below seems to work
sort -t\| -k2,4 input.txt| awk -F'|' '{if (NR==1) print $0} {x=$2 $3 $4} NR>1 {if ($2 $3 $4 != y) {print $0}} {y=x}'
and now I want to pass comma seperated column number list to the script and use shell variable to hold the same and pass that to awk using the below, but it doesnt seem to work.
Without samples it's difficult to guess what you want to do. How about removing the $-signs from awkcolist, splitting it into an array, and using a for loop to run through the array elements to construct your x variable?
In the above column 2,3,4 of the file input.txt are key columns and I have to remove duplicates on these columns. Once that is done I need to make the script generic so that I will accept comma seperated list of columns and file name and script should remove duplicates over the keys.
The first code fragment is working fine when the key column numbers are har coded inside awk but when I try to pass the column list as a variable trying to imitate the first code fragment it isn't working.