【发布时间】:2022-10-17 21:20:45
【问题描述】:
我是 bash 脚本的新手,所以我认为可能有办法做到这一点,但我无法在网上找到我想要的信息。
我需要比较文件夹中的文件,现在我手动浏览它们并运行:
diff -w file1 file2 > file_with_difference
像这样(伪代码)会使我的生活变得更轻松的事情:
for eachfile in folder:
diff -w filei filei+1 > file_with_differencei #the position of the file, because the name can vary randomly
i+=1 #so it goes to 3vs4 next time through the loop,
#and not 2vs3
所以它将 1st 与 2nd、3rd-4th 进行比较,依此类推。 该文件夹总是有偶数个文件。
非常感谢!
【问题讨论】:
-
我不明白您如何选择要比较的文件对?如果我的文件夹包含
config.ini、data.yaml、main.go、output.json,我应该将config.ini与data.yaml进行比较,然后将main.go与output.json进行比较? -
是的,文件夹结构已经建立,文件是成对的,new_file_id_date - old_file_id_date。任务是找出文件的两个版本之间的差异。
-
fwiw : 如果你打算比较同一目录的两个版本,你也可以设置两个目录,
old/和new/,文件有完全相同的名字在他们两个中,只需运行diff old new
标签: bash shell scripting compare