The UNIX Forums  



Forum Sponsor



Go Back   The UNIX Forums > OS Specific Forums > AIX
Home Forums Register Rules & FAQDonate Members List Search Today's Posts Mark Forums Read

AIX Post questions here if you know that only an AIX expert can help.

Reply
 
Submit Tools Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 1 Week Ago
Registered User
 
Join Date: May 2008
Location: Sheffield
Posts: 10
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 1 Week Ago
Registered User
 
Join Date: May 2008
Posts: 9
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
#!/bin/ksh

cat file1.txt | while read line
do
JOBNAME=$(echo ${line} | awk '{print $3}')
LINE2=$(grep -w $JOBNAME file2.txt)
echo "$line $LINE2" >> file3.txt
done

I think it 's OK
Reply With Quote
  #3 (permalink)  
Old 1 Week Ago
Registered User
 
Join Date: May 2008
Location: Sheffield
Posts: 10
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
Got the following result

cat file1.txt | while read line
while: Expression syntax.

from

#!/bin/ksh

cat file1.txt | while read line
do
JOBNAME=$(echo ${line} | awk '{print $3}')
LINE2=$(grep -w $JOBNAME file2.txt)
echo "$line $LINE2" >> file3.txt
done
Reply With Quote
  #4 (permalink)  
Old 1 Week Ago
Registered User
 
Join Date: May 2008
Posts: 9
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
#!/bin/ksh

cat file1.txt | while read line
do
JOBNAME=$(echo ${line} | awk '{print $3}')
LINE2=$(grep -w $JOBNAME file2.txt | awk '{print $2 " " $3}')
echo "$line $LINE2" >> file3.txt
done

it 's better ...
Reply With Quote
  #5 (permalink)  
Old 1 Week Ago
Registered User
 
Join Date: May 2008
Posts: 9
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
Quote:
Originally Posted by Northerner View Post
Got the following result

cat file1.txt | while read line
while: Expression syntax.

from

#!/bin/ksh

cat file1.txt | while read line
do
JOBNAME=$(echo ${line} | awk '{print $3}')
LINE2=$(grep -w $JOBNAME file2.txt)
echo "$line $LINE2" >> file3.txt
done

You have to add the full path and the right name of your file.
For exemple a file in /tmp :
cat /tmp/File1 | while read line
do
JOBNAME=$(echo ${line} | awk '{print $3}')
LINE2=$(grep -w $JOBNAME /tmp/File2 | awk '{print $2 " " $3}')
echo "$line $LINE2" >> /tmp/File3
done
Reply With Quote
  #6 (permalink)  
Old 1 Week Ago
Registered User
 
Join Date: May 2008
Location: Sheffield
Posts: 10
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
I'm sorry I get the same result with full path specified.
Reply With Quote
  #7 (permalink)  
Old 1 Week Ago
Registered User
 
Join Date: May 2008
Posts: 9
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
it ' s amaising !

On my server (AIX), I have created 4 files :
File1 with the following content :
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

My script newscript.ksh (chmod u+x newscript.ksh) :
#!/bin/ksh

cat File1 | while read line
do
JOBNAME=$(echo ${line} | awk '{print $3}')
LINE2=$(grep -w $JOBNAME File2 | awk '{print $2 " " $3}')
echo "$line $LINE2" >> File3
done


I'm running the script $PWD/newscript.ksh

So, I have a new file File3 :
# more File3
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

It's working fine for me.
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 Off
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
KSH Scripting dstaller Shell Programming and Scripting 1 11-16-2005 12:30 PM
HELP! Need HELP scripting! adawg1283 Shell Programming and Scripting 7 09-29-2004 02:48 PM


web tracker

All times are GMT -5. The time now is 12:08 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