This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Split Seven Rows In Per Column

There is only one column in the file,I want to split seven rows in per column

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

the result is

1 2 3 4 5 6 7 
8 9 10 11 12 13 14
15 16 17 18 19 20 21 
22 23 24 25 26 27 28

tip: try to use awk, using a loop for(i=1;i<= NF;i++) if(i%7....

If I can I would ,I am learning perl.Thank you your tip,I will try it

cat a.txt | awk '{for(i=1;i<=NF;i++)print $i"\t"}'|awk '{if (NR%7==0) {print $0} else {printf "%s ",$0}}'> b.txt

There is no connection to bioinformatics and therefore the question must be closed.

1 answer

Your question is not clear, because you said that you have a file that contains only one column, but then you show an example of a file that contains only one row.

case 1: split a file that contains one row and multiple columns

This are the contents of your file:

$: cat filenumbers
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

You want to split it into files containing 7 numbers each:

==> myresultaa.ok <==
1 2 3 4 5 6 7

==> myresultab.ok <==
8 9 10 11 12 13 14

==> myresultac.ok <==
15 16 17 18 19 20 21

==> myresultad.ok <==
22 23 24 25 26 27 28

Code:

sed 's/ /\n/g' filenumbers.txt | split -l 7  - temporary_results_
find . -maxdepth 1 -iname "myresult*" -print0 |  xargs -0 -I filename sh -c 'paste filename -s -d" " > "filename.ok"; rm filename' -- {}

Log in to answer this question.