count=0
cat old_info|while read i
do
cat new_info|while read j
do
count=`expr $count + 1`
echo $count
if [[ $i = $j ]];then
echo "compare response_info pass"
else
echo "Compare response_info error"
echo $i
echo $j
fi
done
done
这个脚本会把i依次和j的每一个值比较,我想要的结果是 每次循环 i和j比较 然后 i 和j各循环一次 然后i和j在比较请问如何改动
shell 循环比对变量是否相等
答案:2 悬赏:30 手机版
解决时间 2021-04-08 21:27
- 提问者网友:凉末
- 2021-04-07 21:09
最佳答案
- 五星知识达人网友:低血压的长颈鹿
- 2021-04-07 21:40
awk '{
if(FILENAME=="'old_info'")
{
Filekey[$1]=$0
}
if(FILENAME=="'new_info'")
{
if($0 in Filekey)
{
print $0 >>"sameline"
print "compare response_info pass" >>"sameline"
}
else
{
print $0 >>"diffline"
print "Compare response_info error" >>"diffline"
}
}
}' old_info new_info
if(FILENAME=="'old_info'")
{
Filekey[$1]=$0
}
if(FILENAME=="'new_info'")
{
if($0 in Filekey)
{
print $0 >>"sameline"
print "compare response_info pass" >>"sameline"
}
else
{
print $0 >>"diffline"
print "Compare response_info error" >>"diffline"
}
}
}' old_info new_info
全部回答
- 1楼网友:荒野風
- 2021-04-07 22:23
awk 'NR==FNR{a[FNR]=$0;next} $0==a[FNR]{print "compare response_info pass
"} $0!
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯