![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to combine 2 different files | rdasari | HP-UX | 1 | 03-17-2008 02:19 PM |
| combine two files | fredao1 | Shell Programming and Scripting | 1 | 01-08-2007 06:29 PM |
| Combine 2 files | Nekki | UNIX for Dummies Questions & Answers | 2 | 11-30-2005 11:46 PM |
| How to combine 2 files | ravi.sadani19 | Shell Programming and Scripting | 2 | 07-12-2005 01:04 AM |
| how to combine two files | tao | UNIX for Dummies Questions & Answers | 4 | 03-21-2002 07:38 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Need To Combine 2 Files
I have 2 files that I need to combine.
One file is looks like this: 71664107;1;1;05-FEB-07;12-FEB-07; The other file looks like this: U;71664107;dummy;Pirovano;M;04-SEP-75;Georgia;MI;1;1;31;S;S;;;Y;05-02-2007;0;12-FEB-07; I need to combine both files together. I need the shorter file added to the end of the longer file based on the common # 71664107. I have tried using get line but sometimes it does not work. Any suggestions? |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Quote:
U;71664107;dummy;Pirovano;M;04-SEP-75;Georgia;MI;1;1;31;S;S;;;Y;05-02-2007;0;12-FEB-07; So you might be able to use: nawk 'BEGIN { FS=";" } { print $0 $2";"$9";"$10";"$17";"$19";" }' <longfile> |
|
#3
|
|||
|
|||
|
No The Files Are Not The Same
I have two files that I need to combine. The information is similar but 1 file is larger than the other. They must be combined.
Thanks |
|
#4
|
||||
|
||||
|
If the files are sorted correctly, then try using join...
Code:
$ head file[12] ==> file1 <== 71664107;1;1;05-FEB-07;12-FEB-07; ==> file2 <== U;71664107;dummy;Pirovano;M;04-SEP-75;Georgia;MI;1;1;31;S;S;;;Y;05-02-2007;0;12-FEB-07; $ join -t ';' -1 2 -2 1 file2 file1 71664107;U;dummy;Pirovano;M;04-SEP-75;Georgia;MI;1;1;31;S;S;;;Y;05-02-2007;0;12-FEB-07;;1;1;05-FEB-07;12-FEB-07; |
|
#5
|
|||
|
|||
|
If they are in sorted format and lines matches. just use below command.
paste long_file short_file |
|||
| Google The UNIX and Linux Forums |