I have a file with 10,671 columns. I am trying to split it into 10 smaller files, each with 1000 columns until all columns have been printed, named file_transposed01, file_transposed02, ... file_transposed10. I am printing the first column of the file as the first column for every new sub-file.I know it is possible to do this by row number using awk. I am trying to adapt this approach using NF instead of NR to split by columns:awk 'BEGIN{$1;}NF%1000==2{x=masterfile_transposed++i;a[i]=x;print f>x;}{print > x}' masterfileBut it gives an error: expression for `>' redirection has null string value. I am not sure what is wrong with my syntax. Is it possible to do this task using awk?How can I make this approach work, or is there a better approach to take?
splitting a file by column number
text processing;awk
awk -v ncols=1000 '    {        f=1        file = file_ f        for (i=1; i <= NF; i++) {            printf %s%s, $i, OFS > file            if (i % ncols == 0) {                print  > file                f++                file = file_ f            }        }        print  > file    }' file