![]() |
|
|||||||
| Home | Forums | Register | Rules & FAQ | Donate | 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. |
![]() |
|
|
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 |
|
|
|
|||
|
Code:
nawk 'NR == FNR{rec[$1] = $2" " $3; next}
{ print $0 " " rec[$3]}
' 64491_merge1.d 64491_merge.d
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 |
| Forum Sponsor |
|
|
|
|||
|
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 |
|
|||
|
The output from this awk command is
0508 0601 LVTS4687 58 1ltreb_shu1l110 shu1l110 0509 0108 LVTS4687 58 1ltreb_shu1l110 shu1l110 0509 0108 LVTS4687 58 1ltreb_shu1l110 shu1l110 0509 0108 LVTS4687 58 1ltreb_shu1l110 shu1l110 0508 2206 LVTS5035 98 1sy_unix_live_dmz_duplex_15_35 srublae03-mgt 0508 2206 LVTS5035 98 1sy_unix_live_dmz_duplex_15_35 srublae03-mgt 0508 2206 LVTS5035 98 1sy_unix_live_dmz_duplex_15_35 srublae03-mgt 0508 2206 LVTS5430 98 1 0508 2206 LVTS5430 98 1 0508 2206 LVTS5430 98 1 0508 2206 LVTS5431 98 1lmurb_shu1l282 shu1l282-sy 0508 2206 LVTS5431 98 1lmurb_shu1l282 shu1l282-sy 0508 2206 LVTS5431 98 1lmurb_shu1l282 shu1l282-sy 0506 0920 LVTS5750 41 3nw_unix_live_dmz_duplex_35_35 NRUCCAE09-MGT 0506 0920 LVTS5750 41 3nw_unix_live_dmz_duplex_35_35 NRUCCAE09-MGT 0506 0920 LVTS5750 41 3nw_unix_live_dmz_duplex_35_35 NRUCCAE09-MGT 0506 0920 LVTS5750 41 3nw_unix_live_dmz_duplex_35_35 NRUCCAE09-MGT 0506 0920 LVTS5750 41 3nw_unix_live_dmz_duplex_35_35 NRUCCAE09-MGT 0506 0920 LVTS5750 41 3nw_unix_live_dmz_duplex_35_35 NRUCCAE09-MGT Which is almost there apart from there being no space between parm5 and 6 and also parm 4 is reduced to the last 2 digits. Apologies for my ignorance on this but I have never used "awk" before. The file should look like this 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 0508 2206 LVTS5430 98 1 0508 2206 LVTS5430 98 1 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 Is it possible to format the file so each parm starts in a specific column for example Parm1 in Col1 Parm2 in Col6 Parm3 in Col12 Parm4 in Col22 Parm5 in Col27 Parm6 in Col30 Parm7 in Col65 |
|
|||
|
That sounds like a simple printf specifier.
Code:
awk whatever ... |
awk '{ printf ("%5s%6s%9s%5s%3s%35s%s\n", $1, $2, $3, $4, $5, $6, $7) }'
I don't see anything which would be reducing $6 to just two characters. |
|
|||
|
The original file2 had the following
0508 2206 LVTS5431 98 1 0506 0920 LVTS5750 141 3 but the output to file3 shows 0506 0920 LVTS5750 41 3nw_unix_live_dmz_duplex_35_35 NRUCCAE09-MGT where the 141 is truncated to 41 the final output I would like to see so that each parm is alligened in the specific columns Starting in column 1 6 12 22 27 30 65 0508 0601 LVTS4687 58 1 ltreb_shu1l110 shu1l110 Last edited by Northerner : 2 Days Ago at 07:51 AM. |
|
|||
|
Whatever is causing that is not happening here, and it's unlear why it would be caused by Radoulov's script; it doesn't alter $6. Might your input file have been corrupted at some point?
|
|
|||
|
It's not showing as aligned any particular way here. Maybe if you post an example with code tags we can see better what you mean. (This regular HTML edit box will squeeze all spaces down to one.)
|
![]() |
| 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 |
| 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 |