Here’s what I’m trying to achieve:
File 1 has contents something like this:
.
.
.
get_time file 10 -max 5 -min 0 abcde
get_time file 9 -max 5 -min 0 abfdf
get_time file 9 -max 5 -avg 3 -min 0 xyyxx
get_time file 10 -max 5 -min 0 abcxx
.
.
.
Meanwhile file 2 just contains:
abcde 8
abfdf 8.5
xyyxx 7.5
abcxx 9
.
.
.
What I need is a file 3 that prints out exactly whats there in file 1, except replace the value in column 3 correspondingly.
So the output should look like:
.
.
.
get_time file 8 -max 5 -min 0 abcde
get_time file 8.5 -max 5 -min 0 abfdf
get_time file 7.5 -max 5 -avg 3 -min 0 xyyxx
get_time file 9 -max 5 -min 0 abcxx
.
.
.
Note: File 1 contains a lot of other stuff that don’t start with “get_time” before and after it. They’re noted as dots in the example above.
Thanks for your help!
Edit: Thanks! Quick follow-up. Another similar file has something like this instead:
get_time file123 tmp 10 -max 5 -min 0 abcde
get_time file foo 9 -max 5 -min 0 abfdf
get_time file43 bar 9 -max 5 -avg 3 -min 0 xyyxx
How would you modify your script? Thanks again
Read file 2 into a hash or dictionary, where the key is the 5-letter tag.
Read file 1 one line at a time, replacing the value in the third column with the value found in the hash or dictionary based on the tag that appears at the end of the line.
Perl
I make no claims that it is superlative Perl; it does seem to work given:
file1
file2
output