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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Merge files of differrent size with one field common in both files using awk shashi1982 Shell Programming and Scripting 2 03-03-2009 07:12 AM
Merge two files whose names are given in other file harshada Shell Programming and Scripting 1 10-01-2008 05:17 AM
MERGE 13 files and add the file name at the end of each record vkr Shell Programming and Scripting 2 08-19-2008 12:57 PM
merge files koti_rama Shell Programming and Scripting 5 12-24-2007 10:59 PM
merge two files in one file nvkuriseti Shell Programming and Scripting 3 08-27-2007 07:06 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-21-2009
daikeyang daikeyang is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 24
merge two files into one file use awk

Hi, guys. I have one question:

I have two files: passwd and shadow (the number of records in these files are not equal)the contents of them are below:

passwd:

**************
ftp:x:24:24:
sshd:x:71:65:
uucp:x:10:14:
brownj:x:5005:1000:
sherrys: x :5006:1000:
...
*************

passwd:
**************
...
ftp:*:13503::
uucp:*:13503::
brownj:ASDFASERE#$#s:0:0
sherrys:GAS3434f#$#$@4:0:0
...
*****************

I want to merge them into a file or a variable called "join", which should have the following contents:
***************
...
ftp:24:*
uucp:10:*
brownj:5005:ASDFASERE#$#s
sherrys:5006:GAS3434f#$#$@4
...
***********************

How can I do this?

Thank you very much for your time in advance

-Keyang
  #2 (permalink)  
Old 03-21-2009
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,937

Code:
 join -t: -o 1.1,1.3,2.2 passwd shadow

  #3 (permalink)  
Old 03-21-2009
daikeyang daikeyang is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 24
Quote:
Originally Posted by fpmurphy View Post
Code:
 join -t: -o 1.1,1.3,2.2 passwd shadow
Hi, fpmurphy.

Your code works, but it has a problem in my case, it always gives me 2 messages:

join: File 1 is not in sorted order
join: File 2 is not in sorted order

Then I user sort command on both of them to get two new files, but still get these messages, do you know what might cause this problem?

Thank you very much for your time in advance

-Keyang
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:39 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0