在文件对之间进行列表比较 [英] Do diff between pairs of a file a list

查看:74
本文介绍了在文件对之间进行列表比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Linux系统上有一个目录,其内容是成对的文件名,如下所示:

I have a directory on my Linux system whose contents are file names in pairs as follows:

 File1a
 File1b
 File2a
 File2b
 File3a
 File3b

我想对File1a和File1b的内容进行比较,并将结果存储在单独的文件中.类似地,对遍历整个列表的其他对执行此操作.可以使用shell脚本来实现吗?

I want to do a diff between the contents of File1a and File1b and store the results in a separate file. Similarly do this over other pairs iterating through the entire list. Can this be achieved with a shell script ?

推荐答案

如果您真的需要依赖文件中的内容,因为您的文件名与您发布的简单模式不匹配(并且您的文件名不包含空格)您可以执行以下操作:

If you really need to rely on what's inside your file because your filenames do not match the simple pattern that you posted (and your filenames don't contain spaces) you can do something like:

xargs -L2 echo < file.txt | while read first second; do
    diff "${first}" "${second}" > "${first}_${second}.diff"
done

否则,请使用@devnull或@mbratch的解决方案.

Otherwise go for @devnull's or @mbratch's solution.

这篇关于在文件对之间进行列表比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆