我有2个文件:文件1和文件2.我想检查并比较文件1和文件2中的文件名以及它们匹配的位置,只使用awk或sed将file_2中的数字插入到新的File_3中
我尝试过使用
cat file.2 | while read line do
答案 0 :(得分:-1)
试试这个:
awk 'NR==FNR { d[$NF]=$1; next } d[$NF] { print d[$NF] FS $0 }' FILE2 FILE1
答案 1 :(得分:-1)
你可以自己定义功能来检查文件。
checkDiff() {
file1=$1
file2=$2
result=$3
rm -rf $result
#check Which one is big based line count
file1Count=$(cat ${file1} | wc -l)
file2Count=$(cat ${file2} | wc -l)
# to check which one need to pass to while loop
if [ $file1Count -gt $file2Count ] ; then
bigFile=$file1
smallFile=$file2
else
bigFile=$file2
smallFile=$file1
fi
#check difference line by line
cat $bigFile | while read line ; do
notpint=$(cat $smallFile | grep "$line")
if [ $? -ne 0 ]; then # if you want to print where they match change "ne" to "eq"
echo $line >> $result
fi
done
}
checkDiff <file1> <file2> <result filename>