Unix/Linux Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Join or Awk

UNIX for Dummies Questions & Answers


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 10-12-2012
jimmyf jimmyf is offline
Registered User
 
Join Date: Oct 2012
Last Activity: 2 May 2015, 4:34 PM EDT
Posts: 68
Thanks: 34
Thanked 0 Times in 0 Posts
Join or Awk

Is is possible to join on unsorted files by a string? Don't want to sort because there is other text that is already in a good format.

I want to replace or join RBOSK-374 in file 2 with NB2781 FGH in file 1.
Any help would be appreciated.


Code:
a.log: RBOSK-374 AAA-B04-D16-K01
a.log: 0 XXX 602 14/1 R14A 
a.log: 2 XXX 119 128/1 R1B 
a.log: 3 XXX 119 128/1 R1B 
a.log: 4 XXX 119 128/1 R1B 
a.log: 5 XXX 231 201/1 R10B 
a.log: 6 XXX 231 201/1 R5C 
b.log: RBOSK-70 NB9292 
b.log: RBOSK-374 NB2781 
b.log: RBOSK-73 JO1794 
b.log: RBOSK-83 OK1987 
b.log: RBOSK-85 LY1983

I would want to file "a" to be like this:

Code:
a.log: NB2781 AAA-B04-D16-K01 
a.log: 0 XXX 602 14/1 R14A 
a.log: 2 XXX 119 128/1 R1B 
a.log: 3 XXX 119 128/1 R1B 
a.log: 4 XXX 119 128/1 R1B 
a.log: 5 XXX 231 201/1 R10B 
a.log: 6 XXX 231 201/1 R5C


Last edited by Scott; 10-12-2012 at 12:58 PM.. Reason: Code tags
Sponsored Links
    #2  
Old Unix and Linux 10-12-2012
Scrutinizer's Unix or Linux Image
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 28 May 2015, 1:03 AM EDT
Location: Amsterdam
Posts: 10,216
Thanks: 334
Thanked 2,697 Times in 2,413 Posts
Try:

Code:
awk 'NR==FNR{A[$1]=$2; next} $1 in A{$1=A[$1]}1' b.log a.log

The Following User Says Thank You to Scrutinizer For This Useful Post:
jimmyf (10-12-2012)
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to use the the join command to join multiple files by a common column evelibertine UNIX for Dummies Questions & Answers 5 07-05-2012 04:15 PM
how to join two files using "Join" command with one common field in this problem? mindfreak UNIX for Dummies Questions & Answers 2 04-13-2012 05:55 AM
Join 2 files with multiple columns: awk/grep/join? InfoSeeker UNIX for Dummies Questions & Answers 3 12-01-2009 07:45 PM
sql,multiple join,outer join issue robbiezr Programming 0 06-05-2009 11:26 PM
join (pls help on join command) summer_cherry Shell Programming and Scripting 1 12-31-2007 04:19 AM



All times are GMT -4. The time now is 08:03 AM.