The command line below works for me
perl -F'\t' -lane'print join ",", @F[1,2]' inputfile
BUT I want to pass a variable list of columns, not necessarily columns 1 and 2 as specified in @F[1,2]
.
For example, based on the total number of columns of the inputfile, I would like to select a random subset "$random-columns"
and pass it to @F[$random-columns]
.
How do I do that?
I tried to first generate a columnList of 5 random column numbers between 1 and 50:
columnList=()
for (( i = 0; i <= 5-1; ++i ))
do
(( randCol = ($RANDOM % 50) + 1 ))
columnList[i]=$randCol
done
Then I did the following to insert the comma:
cols_new=$(IFS=,; echo "${columnList[*]}")
and tried to pass it to the perl command line as below (didn't work):
perl -F'\t' -lane'print join ",", @F[$cols_new]' inputfile