The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 02-19-2007
Registered User
 

Join Date: Jan 2007
Posts: 24
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?
Reply With Quote
Forum Sponsor
  #2  
Old 02-19-2007
Registered User
 

Join Date: Jan 2007
Posts: 366
Quote:
Originally Posted by goodmis
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?
Isn't all the information of the file with the short lines already in the file with the long lines?

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>
Reply With Quote
  #3  
Old 02-19-2007
Registered User
 

Join Date: Jan 2007
Posts: 24
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
Reply With Quote
  #4  
Old 02-19-2007
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,248
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;
Reply With Quote
  #5  
Old 02-21-2007
Registered User
 

Join Date: Feb 2007
Posts: 29
If they are in sorted format and lines matches. just use below command.

paste long_file short_file
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 10:42 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0