Join or Awk | Unix Linux Forums | UNIX for Dummies Questions & Answers

  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: 1 December 2014, 4:52 PM EST
Posts: 66
Thanks: 32
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 01:58 PM.. Reason: Code tags
Sponsored Links
    #2  
Old Unix and Linux 10-12-2012
Scrutinizer's Unix or Linux Image
Scrutinizer Scrutinizer is online now Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 5 March 2015, 10:59 AM EST
Location: Amsterdam
Posts: 9,961
Thanks: 321
Thanked 2,586 Times in 2,312 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

Unix or Linux Image 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 05: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 06:55 AM
Join 2 files with multiple columns: awk/grep/join? InfoSeeker UNIX for Dummies Questions & Answers 3 12-01-2009 08:45 PM
sql,multiple join,outer join issue robbiezr Programming 0 06-06-2009 12:26 AM
join (pls help on join command) summer_cherry Shell Programming and Scripting 1 12-31-2007 05:19 AM



All times are GMT -4. The time now is 12:02 PM.