我有很多 .txt 文件(即 1.txt、2.txt 3.txt ...等)保存在一个目录中,我想检查目录中文件的内容是否相同
所有文件都应该与其他文件进行比较,如果内容相同则打印yes,如果内容不同则打印no
例如:1.txt
a
b
c
2.txt
a
b
c
3.txt
1
2
3
expected output when compare two file 1.txt 2.txt
1.txt 2.txt yes
expected output when compare two file 1.txt 3.txt
1.txt 3.txt no
expected output when compare two file 2.txt 3.txt
2.txt 3.txt no
我试过脚本
#!/bin/sh
for file in /home/nir/dat/*.txt
do
echo $file
diff $file $file+1
done
但这里的问题是它没有给出输出。请提出更好的解决方案,谢谢。
在 bash 中是这样的:
for i in *
do
for j in *
do
if [[ $i < $j ]]
then
if cmp -s $i $j
then
echo $i $j equal
else
echo $i $j differ
fi
fi
done
done
输出:
1.txt 2.txt equal
1.txt 3.txt differ
2.txt 3.txt differ
对不起,我没时间了,我得走了。请,社区的好心人,如果有很大的错误,请随时介入并提供帮助或评论。明天之前我不能回来。对不起。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句