script to rearrange data.

Hello.

I have data in the following format (the spaces at the beginning of lines are included):

                     1         2
           2   0.39621   0.00000
                       1                 2
           2   0.00000+-0.0000           *
                     1         2
           2   0.35160   0.00000
                       1                 2
           2   0.00000+-0.0000           *

I would like to rearrange it so that the file looks like this (2 columns, tab or comma delimited):

FST p-value
0.39621 0.0000+-0.00000
0.35160 0.000+-0.00000

I would even dispense with the part to the right of +- in the second column.

Thank you for any help.

Anders.

I couldn't get your question correctly. Please explain with clear example.

Hi Nila.

I have multiple files from which I want to extract a few values, and combine across files into one file.

So, in one file I have the following written down:

------------------------
Population pairwise FSTs
------------------------


Distance method: Pairwise differences
                     1         2
           1   0.00000
           2  -0.00024   0.00000


------------
FST P values
------------

Number of permutations : 110

                       1                 2
           1           *
           2   0.63964+-0.0497           *

I am want to write a script which will pull out the yellow highlighted values( -0.000024 and the 0.63964), and put these in a tab delimited file that has two columns. So that it will look like this:

-0.000024 0.63964

--

Let me know if this is clearer.

Thank you.

A.

 awk '{if (NF == 3) { if ($2 ~ /[+-]/) { ORS="\n";print $2;} else { ORS=" ";print $2; }}}'  abc.txt


0.39621 0.00000+-0.0000
0.35160 0.00000+-0.0000

If you want to use perl

cat abc.txt | perl -e 'while (<>){chomp; my @cols = split(" "); next unless($#cols == 2);print "$cols[1] "; print"\n" if ($cols[1] =~ m/[+-]/);}'


0.39621 0.00000+-0.0000
0.35160 0.00000+-0.0000

HTH,
PL

one question in the second file

------------
FST P values
------------

Number of permutations : 110

                       1                 2
           1           *
           2   0.63964+-0.0497           *

is there a space between yellowtext and + ??

thank you all for the help. daptal, your code works great.

cheers,

a.