Hi
I have a text file (Input.txt) with two column entries separated by tab as given below:
aaa str1
bbb str2
cccccc str3
dddd str4
eee str3
ssss str2
sdf str3
hhh str1
fff str2
ccc str3
.....
.....
.....
My problem is, I want to write an awk script (say FirstScript) which will call another script (say SecondScript)which will return a string if a match of "str3" is found in the second column. After matching, the string returned by the second script will be written in the third column separated by a tab. If no match is found, the string from the first column will be copied to the corresponding row in the third column.
The desired output OUTPUT.TXT :
aaa str1 aaa
bbb str2 bbb
cccccc str3 xxx
dddd str4 dddd
eee str3 yyy
ssss str2 ssss
sdf str3 zzz
hhh str1 hhh
fff str2 fff
ccc str3 xyz
.....
.....
.....
In the output file, OUTPUT.TXT
cccccc str3 xxx
eee str3 yyy
sdf str3 zzz
ccc str3 xyz
Here the input to the SecondScript are cccccc, eee, sdf and ccc respectively for each row. xxx, yyy, zzz and xyz are returned by the SecondScript.
Please help me.
Thanks in advance.