Separate fields

 awk 'NF==2{s=$1;next}{$(NF+1)=s}1' sort.txt > output.txt 
A_16_P32713632 chr10 90695750 90695810 ACTA2
A_16_P32713635 chr10 90696573 90696633 ACTA2
A_16_P32713680 chr10 90697419 90697479 ACTA2

The command above outputs the data as a string separated by a space in 1 field. I can not seem to figure out how to output the data in 5 separate fields? Thanks :).

Please explain your problem, I guess this post might be a part of your last post http://www.unix.com/shell-programming-and-scripting/252430-name-lats-column-row.html

1 Like

It is part of that post, but I figured since it was a modification of that it might be better to start a new thread. Basically, as is the output is one line with the text separated by a space.

So the below is all one 1 line in 1 field.

 A_16_P32713632 chr10 90695750 90695810 ACTA2 

Can each text be in the line be 5 separate fields? Thanks :).

How are you defining a "field"? If space is your separator, then that is five fields.

1 Like

Field is a column (thinking in excel terms).

So,

A                         B         C              D              E
A_16_P32713632    chr10   90695750   90695810   ACTA2

Thanks :).

Right. So, if spaces are your separator, you have five fields.

You mention excel, so perhaps your problem is "I want to open this in excel but it looks weird". That would have been nice to know. This is what Excel expects for columns and rows in a text flatfile:

awk -v OFS="\t" -v ORS="\r\n" 'NF==2{s=$1;next}{$(NF+1)=s}1' sort.txt > output.txt

Beware that Excel is infamous for mangling data as it sees fit, especially anything that can be mistaken for a date.

1 Like

Thank you very much :).