Reorganize data by using AWK


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Reorganize data by using AWK
# 1  
Old 02-21-2010
Reorganize data by using AWK

I have a file with several rows of info (^SAMPLE.........) and sevaral rows of values (ABCD_1809034 4.390243627784612).
I would like to reorganize the input to desired output defined below.
Thanx in advance!
INPUT
Code:
^SAMPLE = GSM289470
!Sample_title = Sample 3_CAP153242
#ID_REF = 
#VALUE = intensity.
!sample_table_begin
ID_REF    VALUE
ABCD_1809034    4.390243627784612
ABCD_1660305    4.751449155741236
ABCD_1792173    4.8583770449290125
!sample_table_end
^SAMPLE = GSM289503
!Sample_title = Sample 2_CAP152871
#ID_REF = 
#VALUE = intensity.
!sample_table_begin
ID_REF    VALUE
ABCD_1809034    4.4831787445765245
ABCD_1660305    4.677694779133369
ABCD_1792173    4.622344730376334
ABCD_1762337    4.125614747939841
ABCD_1736007    4.193015091225805
!sample_table_end

OUTPUT

Code:
ABCD_1809034    4.390243627784612    GSM289470    Sample 3_CAP153242
ABCD_1660305    4.751449155741236    GSM289470    Sample 3_CAP153242
ABCD_1792173    4.8583770449290125    GSM289470    Sample 3_CAP153242
ABCD_1809034    4.4831787445765245    GSM289503    Sample 2_CAP152871
ABCD_1660305    4.677694779133369    GSM289503    Sample 2_CAP152871
ABCD_1792173    4.622344730376334    GSM289503    Sample 2_CAP152871
ABCD_1762337    4.125614747939841    GSM289503    Sample 2_CAP152871
ABCD_1736007    4.193015091225805    GSM289503    Sample 2_CAP152871

# 2  
Old 02-21-2010
Try:

Code:
awk -F= '/SAMPLE/ { _c3=$NF; } /Sample_title/ { _c4=$NF; } /^ABCD/ { print $0,_c3,_c4 }' file

# 3  
Old 02-21-2010
Thank you very much. working great!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk --> math-operation in data-record and joining with second file data

Hi! I have a pretty complex job - at least for me! i have two csv-files with meassurement-data: fileA ...... (2 Replies)
Discussion started by: IMPe
2 Replies

2. Shell Programming and Scripting

How can I reorganize the text file content for DB import?

Dear Madam / Sir, My Boss need to reorganize :rolleyes: the text file ready for DB import, here show you the requirment and seems not difficult but how to make it by shell script or other programming language effectively. FILE1 : user1,location1,location2,locatoin3,seat1,seat2,seat3... (4 Replies)
Discussion started by: ckwong99
4 Replies

3. Shell Programming and Scripting

Data processing using awk

Hello, I have some bitrate data in a csv which is in an odd format and is difficult to process in Excel when I have thousands of rows. Therefore, I was thinking of doing this in bash and using awk as the primary application except that due to its complication, I'm a little stuck. ... (24 Replies)
Discussion started by: shadyuk
24 Replies

4. Shell Programming and Scripting

Help with parsing data with awk , eliminating unwanted data

Experts , Below is the data: --- Physical volumes --- PV Name /dev/dsk/c1t2d0 VG Name /dev/vg00 PV Status available Allocatable yes VGDA 2 Cur LV 8 PE Size (Mbytes) 8 Total PE 4350 Free PE 2036 Allocated PE 2314 Stale PE 0 IO Timeout (Seconds) default --- Physical volumes ---... (5 Replies)
Discussion started by: rveri
5 Replies

5. Shell Programming and Scripting

awk - change more data

Origin file has got 180 fields. I have to change olny 12th,18th and 52nd one. In a file new.txt I've got those changes in 4 fields (first one is index): I know how to change ONE field with awk array. But my question is: could it be changed more than one field in one single step? ps: one... (5 Replies)
Discussion started by: frajer
5 Replies

6. Shell Programming and Scripting

Commands to reorganize a text file

Hi! I am trying to create a script to reorder the contents of a text file. Below is the text file initially, followed by how I would like it reordered: File initially: --- Initial lines with text and/or numbers Initial lines with text and/or numbers Initial lines with text and/or numbers... (11 Replies)
Discussion started by: gwr
11 Replies

7. Shell Programming and Scripting

Help with data processing, maybe awk

I have a file, first 5 columns are very normal, like "1107",106027,71400,"Y","BIOLOGY",, however, the 6th columns, the user can put comments, anything, just any characters, like new line, double quote, single quote, whatever from the keyboard, like"Please load my previous SOM597G course content in... (3 Replies)
Discussion started by: freelong
3 Replies

8. Shell Programming and Scripting

AWK help. how to compare a variable with a data array in AWK?

Hi all, i have a data array as follows. array=ertfgj2345 array=456ttygkd . . . array=errdjt3235 so number or elements in the array can varies depending on how big the data input is. now i have a variable, and it is $1 (there are $2, $3 and so on, i am only interested in $1). ... (9 Replies)
Discussion started by: usustarr
9 Replies

9. Shell Programming and Scripting

awk - rearange data

Dear All, once again I am encountering a problem with awk. The file looks like this: BroadLeaves 43.6 clc2006 37.6 Conifers 8.3 edge100 5.1 dem30sec 3.9 aspect 1.5 slope 0 dem30sec 58.3 Conifers 28.5 clc2006 7.3 edge100 3 slope 2.4 BroadLeaves 0.4 aspect 0.1 .... ... .. My... (9 Replies)
Discussion started by: creamcheese
9 Replies

10. Shell Programming and Scripting

data format from (4.56 0.7) -> 4.6(7) awk?!

Hi, I have to manipulate a data file which say reads like this {$index $value $error_on_value} aa 4.56 0.7 bb 123.456 0.00987 cc 987654 321 . . in easily human readable format of type aa 4.6(7) bb 123.456(1) cc 9.877(3)e+05 value rounded to 4.6 with error of 0.7 on the last... (4 Replies)
Discussion started by: ahan
4 Replies
Login or Register to Ask a Question