我有2个文件。
File 1
abc,116,39.1,,2014-01-15,0,0
def,7156,49.1,,2014-01-15,0,0
ghi,1234,22.1,,2014-01-15,0,0
jkl,5678,10.2,,2014-01-15,0,0
File 2:
abc,116,59.1,,2014-01-15,0,0
def,7156,49.1,39.1,2014-01-15,0,0
所需的o / p: 将file2中的前2列与file1进行比较。两个文件中匹配的记录应放在以下格式的新文件中。
abc,116,39.1,,2014-01-15,0,0
abc,116,59.1,,2014-01-15,0,0
def,7156,49.1,,2014-01-15,0,0
def,7156,49.1,39.1,2014-01-15,0,0
请帮忙。
答案 0 :(得分:1)
while read line
do
head=$(echo $line |cut -d , -f 1)
grep "^"$head file1 >> file3
echo $line >> file3
done < file2