这就是我想要实现的目标:
文件1:
test fileb 4578;
test filec 7689;
test filey 9978;
test filez 12300;
文件2:
test fileb 1;
test filec 2;
test filey 3;
文件 1 变为:
test fileb 1;
test filec 2;
test filey 3;
test filez 12300;
% awk 'NR==FNR{a[$1,$2]=$3;next}{if(a[$1,$2])$3=a[$1,$2];print}' file2 file1
test fileb 1;
test filec 2;
test filey 3;
test filez 12300;
你可以试试:
while read f1 f2 f3
do
X=$(grep "$f1 $f2" file2)
if [ -n "$X" ]; then
echo "$X"
else
echo "$f1 $f2 $f3"
fi
done <file1
这可能对您有用(GNU sed):
sed 's|\(\S* \S*\).*|/\1/c\\&|' file2 | sed -i -f - file1