Computing.Net > Forums > Unix > Awk: parsing multiple files into one

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Awk: parsing multiple files into one

Reply to Message Icon

Name: Horus
Date: June 17, 2009 at 06:00:29 Pacific
OS: Linux i686
Subcategory: Software Problems
Comment:

Hi,

hopefully someone can help me with this. I have two different data files and I need to parse them into one.

scan1:
3.000000 0.350000 3.000000 30133.768166 7536.733367
3.010000 0.350000 3.000000 30095.744254 7534.987714
3.020000 0.350000 3.000000 30063.943502 7533.352427
3.030000 0.350000 3.000000 30042.434528 7531.945770
3.040000 0.350000 3.000000 30032.624095 7530.835240
3.050000 0.350000 3.000000 30033.924666 7530.041277

scan2:
3.000000 0.350000 3.000000 30155.626929 7538.175239
3.010000 0.350000 3.000000 30129.314365 7536.733917
3.020000 0.350000 3.000000 30107.228293 7535.338720
3.030000 0.350000 3.000000 30092.358928 7534.077845
3.040000 0.350000 3.000000 30085.811542 7533.002854
3.050000 0.350000 3.000000 30087.274675 7532.131323
3.060000 0.350000 3.000000 30095.707161 7531.454071
3.070000 0.350000 3.000000 30109.869329 7530.944246

I want to parse all 5 columns of file1 and columns 4 and 5 into one file under the condition that columns 1-3 are identical. The result should look like this:
3.000000 0.350000 3.000000 30133.768166 7536.733367 30155.626929 7538.175239

I found http://www.computing.net/answers/un... and it parses column 5 from scan2 into a new file under the condition that columns 1 are identical in scan1 and scan2. Currently I also have data files with increasing column 2 instead of column 1 and the above solution doesn't seem to work on that one.

Help would be appreciated, thanks!



Sponsored Link
Ads by Google

Response Number 1
Name: ghostdog
Date: June 18, 2009 at 03:09:56 Pacific
Reply:

awk 'FNR==NR{a[$1,$2,$3]=$4" "$5;next}
{ print $1,$2,$3,a[$1,$2,$3]}' file2 file1

GNU win32 packages | Gawk


0

Response Number 2
Name: Horus
Date: June 18, 2009 at 05:38:36 Pacific
Reply:

thank you, this works :)


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Awk: parsing multiple files into one

gzip multiple files into one www.computing.net/answers/unix/gzip-multiple-files-into-one/7121.html

Awk from two files into one file www.computing.net/answers/unix/awk-from-two-files-into-one-file/6194.html

break large file into multiple file www.computing.net/answers/unix/break-large-file-into-multiple-file/5410.html