diff 忽略注释

发布于 2024-12-25 03:15:59 字数 909 浏览 1 评论 0原文

我正在尝试比较 2 个不同的 apaches 配置目录。 但我想避免版本之间的差异。例如,我将比较 2.2.20 和 2.2.21。

这是我到目前为止所拥有的:

#!/bin/ksh

source=/root/daniel/scripts/test
dest=/root/daniel/scripts/test2

# TODO: rewrite as awk script
delta=`diff -ur $source $dest`

deleted=`echo "$delta" | grep "^Only in ${source}:" | sed "/^Only in ${source}: //"`
added=`echo "$delta"   | grep "^Only in ${dest}:"   | sed "/^Only in ${dest}: //"`
changed=`echo "$delta" | grep '^\+\+\+' | awk '{print $2}'`

print "Files deleted in destination"
echo $deleted
print "Files Added in destination"
echo $added
print "Files Changed in destination"
echo $changed

添加评论。 基本上,我将比较两个配置目录。您可以在 httpd.conf 文件中找到 apache 版本。但我们的想法是在所有比较中忽略版本。

添加评论 2. test 和 test2 是目录,它们不是文件。在这 2 个目录中,您可以找到 apache 的所有配置文件。 或多或少是这样的: + 额外 + httpd.conf + httpd.conf_20110215 + 魔法 + mime.types + 原创 + ssl.crt + ssl.key + 临时

谢谢

I'm trying to compare 2 different apaches config directories.
But I want to avoid the difference between versions. For example I'm going to compare between 2.2.20 and 2.2.21.

This what I have so far:

#!/bin/ksh

source=/root/daniel/scripts/test
dest=/root/daniel/scripts/test2

# TODO: rewrite as awk script
delta=`diff -ur $source $dest`

deleted=`echo "$delta" | grep "^Only in ${source}:" | sed "/^Only in ${source}: //"`
added=`echo "$delta"   | grep "^Only in ${dest}:"   | sed "/^Only in ${dest}: //"`
changed=`echo "$delta" | grep '^\+\+\+' | awk '{print $2}'`

print "Files deleted in destination"
echo $deleted
print "Files Added in destination"
echo $added
print "Files Changed in destination"
echo $changed

Adding a comment.
Basically, I'm going to compare the 2 config directories. You can find the apache version in httpd.conf file. But the idea is to ignore the version in all the comparison.

Adding a comment 2.
The test and test2 are directories, they are not files. In the 2 directories you can find all the config files for apache.
More or less this:
+ extra
+ httpd.conf
+ httpd.conf_20110215
+ magic
+ mime.types
+ original
+ ssl.crt
+ ssl.key
+ temp

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独守阴晴ぅ圆缺 2025-01-01 03:15:59

使用 diff 中的 -I 选项来忽略这些行。

来自man diff

-I RE --ignore-matching-lines=RE

 忽略所有行都与 RE 匹配的更改。

Use the -I option in diff to ignore the lines.

From man diff

-I RE --ignore-matching-lines=RE

      Ignore changes whose lines all match RE.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文