I have two files
FILEA
a/b/c/d
e/f/g/h
i/j/k/l
m/n/o/p
FILEB
i/j/k/l
i want that if lines of FILEB matches lines of FILEA then matching lines in FILEA to be appended by word "MATCH"
NEW FILEA
a/b/c/d
e/f/g/h
i/j/k/l "MATCH"
m/n/o/p
I have tried following script .but not getting desired result.Please Help
for i in `cat FILEB`
do
if [ `grep "$i" FILEA ]; then
`sed '/$i/ s/$/ "MATCH" FILEA`
fi
done
Try:
awk 'NR==FNR{a[$0];next}$0 in a{$0=$0 " MATCH"}1' FILEB FILEA > NEWFILEA
# awk 'NR==FNR{a[x++]=$0}END{for(i=0;i<x;i++)if($0==a)print aFS"\"MATCH\"";else print a}' FILEA FILEB
a/b/c/d
e/f/g/h
i/j/k/l "MATCH"
m/n/o/p
---------- Post updated at 12:50 PM ---------- Previous update was at 12:48 PM ----------
Tried it.It is not generating any error message.But also not generating desired output
How about this ?
awk 'NR==FNR{a[$0]++;next} a[$0]{$0=$0 FS "\"MATCH\""}1' FileB FileA
Yet another one:
awk 'NR==FNR{A[$0]="\"MATCH\""; next}{print $0,A[$0]}' FileB FileA
--
On Solaris use /usr/xpg4/bin/awk rather than awk
/usr/xpg4/bin/awk 'NR==FNR{A[$0]="\"MATCH\""; next}{print $0,A[$0]}' FileB FileA
Working.