The UNIX Forums  



Forum Sponsor





Go Back   The UNIX Forums > Top Forums > Shell Programming and Scripting
Home Forums Register Rules & FAQDonate Members List Search Today's Posts Mark Forums Read

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

Reply
 
Submit Tools Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 2 Days Ago
Registered User
 
Join Date: May 2008
Location: Sheffield
Posts: 5
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
Help with scripting

I have 2 files with a common parm - Jobname

File 1
0507 1202 JOBA
0507 1302 JOBB
0507 1452 JOBC
0507 1552 JOBA
0507 1553 JOBA

File2

JOBA abcdefg server4
JOBB defghij server22
JOBC vwxyz12 server55

I would like to take each line from File1 and match the jobname with the jobname in File 2 and produce File 3 as

0507 1202 JOBA abcdefg server4
0507 1302 JOBB defghij server22
0507 1452 JOBC vwxyz12 server55
0507 1552 JOBA abcdefg server4
0507 1553 JOBA abcdefg server4

Could anyone help please, I'm new to scripting.
Reply With Quote
Forum Sponsor

  #2 (permalink)  
Old 2 Days Ago
Registered User
 
Join Date: Jul 2006
Posts: 113
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
Code:
nawk 'NR == FNR{rec[$1] = $2" " $3; next}

{ print $0 " " rec[$3]}

' 64491_merge1.d 64491_merge.d
output

Code:
0507 1202 JOBA abcdefg server4
0507 1302 JOBB defghij server22
0507 1452 JOBC vwxyz12 server55
0507 1552 JOBA abcdefg server4
0507 1553 JOBA abcdefg server4
Reply With Quote
  #3 (permalink)  
Old 2 Days Ago
Registered User
 
Join Date: May 2008
Location: Sheffield
Posts: 5
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
Talking

Brilliant Thanks very much indeed!
Reply With Quote
  #4 (permalink)  
Old 2 Days Ago
radoulov's Avatar
addict
 
Join Date: Jan 2007
Location: Milan, Italy/Varna, Bulgaria
Posts: 1,012
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
Another one:
(use nawk or /usr/xpg4/bin/awk on Solaris)

Code:
awk 'NR==FNR{x[$1]=$0;next}$NF=x[$NF]' file2 file1
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Scripting dreams5617 SUN Solaris 1 07-06-2006 01:53 PM
difference between AIX shell scripting and Unix shell scripting. haroonec Shell Programming and Scripting 2 04-12-2006 07:12 AM
scripting guru's pls help me with scripting on AIX thatiprashant Shell Programming and Scripting 1 01-20-2006 05:58 PM
HELP! Need HELP scripting! adawg1283 Shell Programming and Scripting 7 09-29-2004 02:48 PM
scripting BigTool4u2 Shell Programming and Scripting 1 11-21-2002 11:20 AM


web tracker

All times are GMT -5. The time now is 08:19 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
UNIX Forum Content Copyright ©1993-2008 SilkRoad Asia All Rights Reserved -Ad Management by RedTyger

Search Engine Optimization by vBSEO 3.1.0