Question: (Closed) Split Seven Rows In Per Column
0
gravatar for 2011101101
5.9 years ago by
2011101101100
2011101101100 wrote:

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
• 1.7k views
ADD COMMENTlink modified 5.9 years ago by Giovanni M Dall'Olio26k • written 5.9 years ago by 2011101101100
2

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

ADD REPLYlink written 5.9 years ago by Michael Dondrup45k
1

You already asked a few questions on this site

Unique-ify the contents of a FASTA-formatted file and associated read numbers

How to reformat a FASTA file to a custom tabular format

A question about RepeatMasker's parameters

and received some valuable responses: but did not validate any answer. Please, do.

ADD REPLYlink modified 5.9 years ago • written 5.9 years ago by Pierre Lindenbaum116k

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

ADD REPLYlink written 5.9 years ago by 2011101101100
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
ADD REPLYlink modified 5.9 years ago • written 5.9 years ago by 2011101101100

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

ADD REPLYlink written 5.9 years ago by Pierre Lindenbaum116k
2
gravatar for Giovanni M Dall'Olio
5.9 years ago by
London, UK
Giovanni M Dall'Olio26k wrote:

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' -- {}
ADD COMMENTlink written 5.9 years ago by Giovanni M Dall'Olio26k
Please log in to add an answer.
The thread is closed. No new answers may be added.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 2401 users visited in the last hour