Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

REQ: Help use table to lookup values 1

Status
Not open for further replies.

Kipnep70

Technical User
Nov 18, 2003
81
US
I have one file that looks like this:

Code:
0,9840_10
1,9840_12
2,9840_9
3,9940_3
4,9840_11
..
..

I also have another file like this:

Code:
2007-11-06 07:50:03 Drive #13 is DOWN-TLD on server.
2007-11-06 07:50:07 Drive #4 is DOWN-TLD on server.
2007-11-06 07:50:10 Drive #15 is DOWN-TLD on server. 
2007-11-06 07:50:10 Drive #0 is DOWN-TLD on server. 
2007-11-06 07:50:13 Drive #18 is DOWN-TLD on server. 
2007-11-06 07:50:16 Drive #2 is DOWN-TLD on server.


I need to replace the number in the second file with the value associated with it in my first file.

Result should look like:

Code:
2007-11-06 07:50:03 Drive 9840_12 is DOWN-TLD on server.
2007-11-06 07:50:07 Drive 9840_1 is DOWN-TLD on server.
2007-11-06 07:50:10 Drive 9840_11 is DOWN-TLD on server. 
..
..


If anybody could give me a start I think I could figure it out. I started learning awk for awhile and then stopped for a few months and now my mind is blank!

Any advice/help would be greatly appreciated.
 
With your posted sample how do you you know that #13 should be replaced with 9840_12 ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV,

Sorry for the confusion. The number attached to the drive name (9840_4) is not correlated with the numbers in the first section, for example the first line reads:

0,9840_10 ..meaning I want to replace drive #0 with 9840_10. The number attached the drive name is not relevant in this scenario. Thanks. If it is easier, just ignore the numbers that are attached with the "_".

Another example:

2007-11-06 07:50:10 Drive #15 is DOWN-TLD on server.

Using this: 15,9840_25

Should read:

2007-11-06 07:50:10 9840_25 is DOWN-TLD on server.


Again, sorry for the confusion. These "drives" use the following format:

drivename_drivenumber and then I correlate them with a target id. (HP-UX)

 
A starting point:
awk -F, 'NR==FNR{a[$1]=$2;next}{for(i in a)sub("#"i" ","#"a" ");print}' onefile anotherfile

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top