|
|
|
|
google site
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
awk 3 files to one based on multiple columns
Hi all,
I have three files, one is a navigation file, one is a depth file and one is a file containing the measured field of gravity. The formats of the files are; navigation file: 2006 320 17 39 0 0 *nav 21.31542 -157.887 2006 320 17 39 10 0 *nav 21.31542 -157.887 2006 320 17 39 20 0 *nav 21.31542 -157.887 depth file: 2006 321 19 17 16 681 dpth 4744.62 0 2006 321 19 17 31 419 dpth 4741.73 0 2006 321 19 17 46 973 dpth 4744.53 0 2006 321 19 18 2 26 dpth 4745.93 0 gravity file: 2006 320 17 39 30 0 cgrv 6992.7 205.6 0 978923 2006 320 17 40 0 0 cgrv 6992.7 205.6 -0.1 978923.1 2006 320 17 40 30 0 cgrv 6992.8 205.7 0 978923.1 2006 320 17 41 0 0 cgrv 6992.8 205.7 0 978923.2 The first five columns of each file are time stamps (year, day, hour, min, seconds). I want to find the latitude (column 8, file 1), longitude (column 9, file 1) and depth (column 9, file 2) for the matching times of file 3 (gravity file). So I need to find when the first 5 columns of file 1 are equal to the first five columns of file 3 and append column 8 and 9 of file 1 to a new version of file 3. I then need to find when the first 5 columns of file 2 are equal to the first five columns of file 3 and append column 9 of file 2 to the new file. Did that make any sense? Thanks! |
| Sponsored Links | ||
|
|
|
|||
|
The way I'd do it would be to read file 3 line by line using sed or awk to get get the columns, untested as I'm not near a Unix machine.
file3=`cat $filename | awk '{FS="(Whatever it is)"};{OFS="Whatever"};{print $1 - $5}` for i in $file3 do awk '{OFS=""};{OFS=""};{/$i/};{print $i $9}' file1 > opfile. do for file 2 done The syntax is worng but the general idea works. Then sort the output file by date. |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Sorting based on Multiple columns | dharmesht | Shell Programming and Scripting | 15 | 05-13-2009 11:44 AM |
| Combine multiple columns from multiple files | martva | Shell Programming and Scripting | 5 | 12-02-2008 09:23 AM |
| Joining two files based on columns/fields | rudoraj | Shell Programming and Scripting | 11 | 09-06-2008 05:47 PM |
| contactenate columns from multiple files | coolnaps | Shell Programming and Scripting | 2 | 05-03-2008 07:01 PM |
| Compare multiple columns between 2 files | stevesmith | Shell Programming and Scripting | 15 | 09-20-2006 01:04 PM |