The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Combining two files hemangjani Shell Programming and Scripting 7 06-13-2007 11:32 PM
Combining Two Files bat711 Shell Programming and Scripting 3 10-05-2005 02:26 PM
Combining files Enda Martin UNIX for Dummies Questions & Answers 2 07-20-2001 11:31 AM
combining files apalex UNIX for Dummies Questions & Answers 3 06-19-2001 10:49 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 10-17-2008
scriptarg scriptarg is offline
Registered User
  
 

Join Date: Jul 2007
Location: North Carolina
Posts: 6
Cool need help sorting and combining files

I have 2 files with many lines.

File one example:
CN=VXX,CN=ug88888,OU=America,OU=State,OU=VXX,
File two example:
ul22222 Jon Smith
ug8888 Mildred Apple
I need a routine that will take the ug88888 portion of the first file and pull out the corresponding full line in file two. Then add the two together so the final output is
ug8888 Mildred Apple CN=VXX,CN=ug88888,OU=America,OU=State,OU=VXX,

Thanks,
  #2 (permalink)  
Old 10-17-2008
scriptarg scriptarg is offline
Registered User
  
 

Join Date: Jul 2007
Location: North Carolina
Posts: 6
Correction

Sorry, let me try that again.
I have 2 files with many lines.

File one example:
CN=VXX,CN=ug8888,OU=America,OU=State,OU=VXX,
File two example:
ul22222 Jon Smith
ug8888 Mildred Apple
I need a routine that will take the ug8888 portion of the first file and pull out the corresponding full line in file two. Then add the two together so the final output is
ug8888 Mildred Apple CN=VXX,CN=ug8888,OU=America,OU=State,OU=VXX,

Thanks,
  #3 (permalink)  
Old 10-17-2008
shamrock shamrock is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2007
Location: USA
Posts: 753

Code:
file1
ul22222 Jon Smith
ug88888 Mildred Apple

file2
CN=VXX,CN=ug88888,OU=America,OU=State,OU=VXX,

awk '{
   if (NR==FNR)
      x[$1] = $0
   else {
      FS=","
      split($2,a,"=")
      if (x[a[2]])
         print x[a[2]], $0
   }
}' file1 file2


Last edited by shamrock; 10-17-2008 at 09:22 PM..
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 07:38 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