script to rearrange data.


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script to rearrange data.
# 1  
Question script to rearrange data.

Hello.

I have data in the following format (the spaces at the beginning of lines are included):
Code:
                     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):
Code:
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.

Last edited by Scott; 02-24-2010 at 08:26 PM.. Reason: Please use code tags
# 2  
Rearrange the data

I couldn't get your question correctly. Please explain with clear example.
# 3  
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:
Code:
------------------------
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:
Code:
-0.000024 0.63964

--

Let me know if this is clearer.

Thank you.

A.

Last edited by Scott; 02-24-2010 at 08:27 PM.. Reason: Please use code tags
# 4  
Code:
 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

Code:
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
# 5  
one question in the second file
Code:
------------
FST P values
------------

Number of permutations : 110

                       1                 2
           1           *
           2   0.63964+-0.0497           *

is there a space between yellowtext and + ??

Last edited by Scott; 02-24-2010 at 08:28 PM.. Reason: Code tags... and please STOP using Yellow font colour :)
# 6  
MySQL

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

cheers,

a.
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #804
Difficulty: Medium
Statistical signal processing is an approach which processes signals as stochastic processes, utilizing their statistical properties to perform signal processing tasks.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

A cleaner way to rearrange column

Hello, I have some tab delimited text data, index name chg_p chg_m 1 name,1 1 0 2 name,2 1 1 3 name,3 1 0 4 name,4 1 0 5 name,5 1 1 I need to duplicate the "index" column, call it "id" and insert it after the... (8 Replies)
Discussion started by: LMHmedchem
8 Replies

2. Shell Programming and Scripting

Rearrange Lines with awk

I need to rearrange the lines in the input file in the example below: Input: LG1 R500 A-170 F1:81 F1:22 F2:32 F1:71 LG1 R700 A-203 F2:17 E2:18 LG1 R700 B-224 E1:9 LG2 R500 C-235 E2:9 F2:17 Output: LG1 R500 A-170 F1:81 LG1 R500 A-170 F1:22 LG1 R500 A-170 F2:32 LG1 R500 A-170... (2 Replies)
Discussion started by: aydj
2 Replies

3. Shell Programming and Scripting

Using awk to rearrange fields

Hi, I am required to arrange columns of a file i.e make the 15th column into the 1st column. I am doing awk 'begin {fs=ofs=","} {print $15,$1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14}' ad.data>ad.csv the problem is that column 15 gets to column 1 but it is not comma separated with the... (10 Replies)
Discussion started by: seddoubt
10 Replies

4. Shell Programming and Scripting

how to rearrange a matrix with awk

Hi, every one. I have two files ,one is in matrix like this, one is a list with the same data as the matrix. AB AE AC AD AA AF SA 3 4 5 6 4 6 SC 5 7 2 8 4 3 SD 4 6 5 3 8 3 SE 45 ... (5 Replies)
Discussion started by: xshang
5 Replies

5. Shell Programming and Scripting

Using awk to rearrange data according to date

Hi, I have a large data frame as shown below, where data is separated into years. 10 May 2011 Created: 10 May 11 15:05 GMT Scale: SIO-2005 and others GC-MD, Cape Grim, Tasmania, Lat.: 40.68S, Lon.: 144.69E, Alt: 94m above sea level You can use the following format in Fortran to read data... (4 Replies)
Discussion started by: gd9629
4 Replies

6. Shell Programming and Scripting

Rearrange the text file

Gents, I have a large file and each line of the file contains more than 200 bytes.Please let me a way to have the new line to start when the word "FIT" appears. I was trialling with 'tr' command but i am not sure how to get it based on bytes and so it wasn't working... Current... (3 Replies)
Discussion started by: appu2176
3 Replies

7. Shell Programming and Scripting

Rearrange data from 2 files

Dear All, I have the below files A file contains 1473 1649 1670 1758 1767 1784 B file contains 1242 1246 1264 1268 1284 (3 Replies)
Discussion started by: yahyaaa
3 Replies

8. Shell Programming and Scripting

rearrange a file

hi! in awk, i have a file like this: Trace1: WRIT,Trace2: BLAN,Trace3: BLAN, -47.2120018005371,,,39815.4809027778 -46.3009986877441,,,39815.4809027778 -46.277000427246,,,39815.4809143519 -46.7389984130859,,,39815.4809259259 -46.3460006713867,,,39815.4809259259... (10 Replies)
Discussion started by: riderman
10 Replies

9. UNIX for Dummies Questions & Answers

Help rearrange the content of the file.

Hi all, I need to rearrange the content of the file. I need to move line 1 to 4, 2 to 3, 3 to 2, and 4 to 1. IPlease help. I was thinking about using head and tail command. Here is the original file. aa bb cc dd Here is what I need it to be. dd cc bb aa Thanks. (6 Replies)
Discussion started by: sirrtuan
6 Replies

10. Shell Programming and Scripting

Need help with a script to rearrange columns

I have a file that is semi-colon delimited and the column headers are always the same but the column number is totally random each time this file is generated. I don't have the skills to make a script for this so maybe someone can help. I would like to be able to take this file which has over... (11 Replies)
Discussion started by: n3al10
11 Replies

Featured Tech Videos