![]() |
|
|||||||
| Home | Forums | Register | Rules & FAQ | Donate | Members List | Search | Today's Posts | Mark Forums Read |
| AIX Post questions here if you know that only an AIX expert can help. |
![]() |
|
|
Submit Tools | Thread Tools | Search this Thread | Display Modes |
|
|||
|
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. |
| Forum Sponsor |
|
|
|
|||
|
#!/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 |
| Forum Sponsor |
|
|
|
|||
|
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 |
|
|||
|
Quote:
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 |
|
|||
|
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. |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
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 |