I would use awkfor this. Not sure if you want to have 5 columns per file, as you mentioned that you have 250k columns that would create 50K files, but here is what you need to start:
awk '{
y=1
for(i=1;i<NF;i++) {
if(i%5==0) {
print $i > "text"y".txt"
y+=1
continue
}
printf "%s ",$i >"text"y".txt"
}
print $NF > "text"y".txt"}' file
Test:
$ cat file
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
$ awk '{
y=1
for(i=1;i<NF;i++) {
if(i%5==0) {
print $i > "text"y".txt"
y+=1
continue
}
printf "%s ",$i >"text"y".txt"
}
print $NF > "text"y".txt"}' file
$ head text*
==> text1.txt <==
AA BB CC DD EE
NN OO PP QQ RR
==> text2.txt <==
FF GG HH II JJ
SS TT UU VV WW
==> text3.txt <==
KK LL MM
XX YY ZZ
source
share