Hi All,
I have one file with two columns separated by tab.
I need to search for second column value of this file in the 5 column of another file. If the match is found replace the 5th column of second file with entire row of the first file.
e.g.
file1
123 D.abc
234 D.rde
4563 D.wedr
file2
wqjksw 123213 dewdqwe 23123 D.abc wswsw
wqjksw 123213 asasaasa 12345 D.abc
wqjksw 123213 asasaasa 12345 D.rde
wqjksw 123213 dewdqwe 23123 D.wedr wswsw
wqjksw 123213 dewdqwe 23123 D.awec wswsw
output file should be
wqjksw 123213 dewdqwe 23123 123 D.abc wswsw
wqjksw 123213 asasaasa 12345 123 D.abc
wqjksw 123213 asasaasa 12345 234 D.rde
wqjksw 123213 dewdqwe 23123 4563 D.wedr wswsw
Since the second file will be huge it would make sence if we first do search operation and the do replacement for each of the rows of first file.
I have writteh below code but its not working.
appreciate your help.
filearray=( `cat filter.txt | tr '\n'`)
rm temp1.txt outputfile.txt
for ((i=0; i<${#filearray[@]}; i++))
{
awk ' if(${filearray[$i]} ~ /$5/) { print $0 }' datafile.txt >> temp1.txt
awk ' {$5=${filearray[$i]} } temp1.txt >> outputfile.txt
}