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
ksh scripting help praveenbvarrier Shell Programming and Scripting 1 04-15-2008 11:19 AM
sql scripting help sam786 Shell Programming and Scripting 3 12-10-2007 12:31 PM
difference between AIX shell scripting and Unix shell scripting. haroonec Shell Programming and Scripting 2 04-12-2006 09:12 AM
scripting guru's pls help me with scripting on AIX thatiprashant Shell Programming and Scripting 1 01-20-2006 07:58 PM
Scripting? woofie What's on Your Mind? 1 03-09-2005 07:03 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 05-09-2008
Northerner Northerner is offline
Registered User
  
 

Join Date: May 2008
Location: Sheffield
Posts: 11
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.
  #2 (permalink)  
Old 05-09-2008
aju_kup aju_kup is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 189

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

  #3 (permalink)  
Old 05-09-2008
Northerner Northerner is offline
Registered User
  
 

Join Date: May 2008
Location: Sheffield
Posts: 11
Talking

Brilliant Thanks very much indeed!
  #4 (permalink)  
Old 05-09-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,915
Another one:
(use nawk or /usr/xpg4/bin/awk on Solaris)


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

  #5 (permalink)  
Old 05-12-2008
Northerner Northerner is offline
Registered User
  
 

Join Date: May 2008
Location: Sheffield
Posts: 11
Having tested this on the simple files I provided it appears it doesn't work on the more complexed files. The first file has 6 field separated by blanks

File1

LVTS4687 LVTSHPLON ltreb_shu1l110 LVTS4687 LVTSHPLON shu1l110
LVTS1457 LVTSHP sy_unix_live_rooma_onsite_35_35 LVTS1457 LVTSHP syhp10
LVTS5035 LVTSHP sy_unix_live_dmz_duplex_15_35 LVTS5035 LVTSHP srublae03-mgt
LVTS1786 LVTSHPLON lmurb_shu1l282 LVTS1786 LVTSHPLON shu1l282-sy
LVTS5431 LVTSHPLON lmurb_shu1l282 LVTS5431 LVTSHPLON shu1l282-sy
LVTS5750 LVTSHP nw_unix_live_dmz_duplex_35_35 LVTS5750 LVTSHP NRUCCAE09-MGT
LVTS5430 LVTSHP nw_unix_live_dmz_duplex_15_35 LVTS5430 LVTSHP nwhp3
LVTS4021 LVTSHP nw_unix_live_phase4_duplex_35_90 LVTS4021 LVTSHP nhu1u282

The second file has 5 fields
File 2
0508 0601 LVTS4687 58 1
0509 0108 LVTS4687 58 1
0509 0108 LVTS4687 58 1
0509 0108 LVTS4687 58 1
0508 2206 LVTS5035 98 1
0508 2206 LVTS5035 98 1
0508 2206 LVTS5035 98 1
0508 2206 LVTS5430 98 1
0508 2206 LVTS5430 98 1
0508 2206 LVTS5430 98 1
0508 2206 LVTS5431 98 1
0508 2206 LVTS5431 98 1
0508 2206 LVTS5431 98 1
0506 0920 LVTS5750 141 3
0506 0920 LVTS5750 141 3
0506 0920 LVTS5750 141 3
0506 0920 LVTS5750 141 3
0506 0920 LVTS5750 141 3
0506 0920 LVTS5750 141 3


and the result would need to look like

File3
0508 0601 LVTS4687 58 1 ltreb_shu1l110 shu1l110
0509 0108 LVTS4687 58 1 ltreb_shu1l110 shu1l110
0509 0108 LVTS4687 58 1 ltreb_shu1l110 shu1l110
0509 0108 LVTS4687 58 1 ltreb_shu1l110 shu1l110
0508 2206 LVTS5035 98 1 sy_unix_live_dmz_duplex_15_35 srublae03-mgt
0508 2206 LVTS5035 98 1 sy_unix_live_dmz_duplex_15_35 srublae03-mgt
0508 2206 LVTS5035 98 1 sy_unix_live_dmz_duplex_15_35 srublae03-mgt
0508 2206 LVTS5430 98 1 nw_unix_live_dmz_duplex_15_35 nwhp3
0508 2206 LVTS5430 98 1 nw_unix_live_dmz_duplex_15_35 nwhp3
0508 2206 LVTS5430 98 1 nw_unix_live_dmz_duplex_15_35 nwhp3
0508 2206 LVTS5431 98 1 lmurb_shu1l282 shu1l282-sy
0508 2206 LVTS5431 98 1 lmurb_shu1l282 shu1l282-sy
0508 2206 LVTS5431 98 1 lmurb_shu1l282 shu1l282-sy
0506 0920 LVTS5750 141 3 nw_unix_live_dmz_duplex_35_35 NRUCCAE09-MGT
0506 0920 LVTS5750 141 3 nw_unix_live_dmz_duplex_35_35 NRUCCAE09-MGT
0506 0920 LVTS5750 141 3 nw_unix_live_dmz_duplex_35_35 NRUCCAE09-MGT
0506 0920 LVTS5750 141 3 nw_unix_live_dmz_duplex_35_35 NRUCCAE09-MGT
0506 0920 LVTS5750 141 3 nw_unix_live_dmz_duplex_35_35 NRUCCAE09-MGT
0506 0920 LVTS5750 141 3 nw_unix_live_dmz_duplex_35_35 NRUCCAE09-MGT


this file comprises of field 1 2 3 4 5 of file2 and field 3 and 6 of file1
  #6 (permalink)  
Old 05-12-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,915
It seems quite easy, did you try to adapt the code yourself?


Code:
awk 'NR==FNR{_[$1]=$3 FS $6;next}$NF=$NF _[$3]' file1 file2>file3

  #7 (permalink)  
Old 05-12-2008
aju_kup aju_kup is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 189
HTML Code:
Now your format is different then earlier
Closed Thread

Bookmarks

Tags
solaris

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 01:03 PM.


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