【发布时间】:2017-04-16 09:33:50
【问题描述】:
我正在尝试使用 unix 比较两个文件并返回成功(如果 file1 内容与 file2 匹配)或如果不匹配则返回失败并显示不匹配的记录
file1 的内容:
columnA1 columnA2
121 ab354664
columnB1 columnB2
143 be000431
ColumnC1 columnC2
001 21uy7732
file2 的内容:
columnA1 columnA2
121 ab354664
columnB1 columnB2
143 be000431
columnC1 columnC2
431 66575wqq
我有以下代码:
if (grep -v "column" $file1) == (grep -v "column" $file2)
then
echo -e "match"
else
echo -e "dont match"
grep -B 1 -v "column" $file
fi
它抛出错误
syntax error near unexpected token `=='
我不确定是否可以使用比较操作来比较两个不同文件中的字符串。
请提出建议。
【问题讨论】:
-
您可以在某些情况下使用
==来比较两个字符串,但您没有两个字符串!但是你为什么不直接做diff file1 file2呢? -
你在使用
bash吗?作为你的原生 shell 还是其他? -
是的,我只使用 bash
标签: unix if-statement grep