How to split a file with 250k columns vertically?

awk, unix

Solution

Using awk, you can adjust n to the number you expect.

awk '{for (i=1;i<=NF;i++)
         printf (i%n==0||i==NF)?$i RS:$i FS > "File" int((i-1)/n+1) ".txt"
      }' n=5 file

Problem

I need to split a file with 250k based on the size (preferable) or number of columns to several (~5) chunks. I am aware of `split` command for row-wise splitting, but don't know if there is any similar function to split column-wise. The number of columns in my file are not even, so the chunks cannot have equal number of columns. Input: ``` AA BB CC DD EE FF GG HH II JJ KK LL MM NN OO PP QQ RR SS TT UU VV WW XX YY ZZ ``` Desired output: `File1` ``` AA BB CC DD NN OO PP QQ ``` `File2` ``` EE FF GG HH RR SS TT UU ``` `File3` ``` II JJ KK LL MM VV WW XX YY ZZ ```

Original source