我正在检查两个文件夹(和)diff -rq
之间的差异。我不想知道文件夹是否有任何新文件,因为这是预期的。我如何确保这些信息不会出现?A
B
A
文件上的 diff3 没有发现差异:
$ grep -P '\[\[.*?\]\]' -o intro.tex | sort > A.txt
$ grep -P '\[\[.*?\]\]' -o intro.tex | sort | uniq > B.txt
$ grep '\\pnum %% \[\[' intro.tex | sed 's/\\pnum %% //' | sort > C.txt
$ diff3 A.txt B.txt C.txt | wc -l
0
diff3 在运行相同命令的进程替换上发现了差异:
$ diff3 \
<(grep -P '\[\[.*?\]\]' -o intro.tex | sort) \
<(grep -P '\[\[.*?\]\]' -o intro.tex | sort | uniq) \
<(grep '\\pnum %% \[\[' intro.tex | sed 's/\\pnum %% //' | sort) | wc -l
95
为什么?有任何想法吗?
最小复制器:
$ echo test > a
$ diff3 a a a
$ diff3 <(cat a) <(cat a) <(cat a)
====1
1:1c
test
2:0a
3:0a
我有2个目录
$ tree dir{1..2}
dir1
├── file1
└── file2
dir2
├── file1
└── file2
我想使用 ansible 将 dir1 中的所有文件与 dir2 中的所有文件进行比较,并像这样打印差异
output:
${file1} from ${dir1}:
diff content
${file1} from ${dir2}:
diff content
它将遍历所有文件以打印它们的差异
下面是需要修改的ansible片段
---
- name: Compare files in two directories
hosts: localhost
gather_facts: false
tasks:
- name: Find files in directory 1
find:
paths: ~/dir1
file_type: file
register: dir1_files
- name: Find files in directory 2
find:
paths: ~/dir2
file_type: file
register: dir2_files
- name: Compare files
shell: diff dir1/file1 dir2/file1 ## how can I make sure path changes but filenames stay same using variables
loop: "{{ dir1_files.files }}"
register: diff_output
changed_when: false
failed_when: diff_output.rc == 1
- name: Print differences
debug:
msg: |
{{ item.item.path }} from dir1:
{{ item.stdout }}
{{ item.item.path }} from dir2:
{{ item.stdout }}
loop: "{{ diff_output.results }}"
when: item.stdout_lines | length > 0
对于 Vladimir 的回答中的建议代码,我得到以下输出
TASK [debug] *****************************************************************************************************************************************
ok: [localhost] => {
"msg": "file2 from dir1: \n 1,2c1,2\n < abc123\n < def456\n ---\n > abc101\n > def111\nfile2 from dir2: \n 1,2c1,2\n < abc123\n < def456\n ---\n > abc101\n > def111\nfile1 from dir1: \n 1,2c1,2\n < 123abc\n < 456def\n ---\n > 101abc\n > 111def\nfile1 from dir2: \n 1,2c1,2\n < 123abc\n < 456def\n ---\n > 101abc\n > 111def\n"
}
我有以下文件:
一个.txt
1
2
11
22
33
444
b.txt
1
2
3
11
22
33
555
我想从 a.txt 中检索 b.txt 上不存在的行。
我试过了:
diff a.txt b.txt -d
2a3
> 3
6c7
< 444
---
> 555
但我希望输出是
444
仅有的。有没有办法在差异上放置某种过滤器?
我想git
使用类似于git
描述“合并冲突”的语义来合并两个非基于文本文件。
例如,假设我有两个内容相似但不相同的文本文件,名为file.1
和file.2
。我想将这两个文件合并到第三个文件中,如下所示:
hypothetical-merge-utility file.1 file.2 file.merged
我希望它产生file.merged
,它将以类似于以下的方式列出文件内容和每个差异:
common line 1 ...
common line 2 ...
common line 3 ...
<<<<<<< file.1
something unique from file.1
a second line of something unique from file.1
======= file.2
something unique from file.2
>>>>>>> end of diff
common line 4 ...
common line 5 ...
<<<<<<< file.1
something unique from file.1
======= file.2
something unique from file.2
a second line of something unique from file.2
>>>>>>> end of diff
common line 6 ...
common line 7 ...
... etc. ...
换句话说,我希望和之间的每个差异file.1
看起来file.2
类似于git
“合并冲突”的表示。
我不在乎是否使用了 , 和 以外<<<<<<<<
的========
分隔符>>>>>>>>
。
我知道有许多实用程序可用于在 linux 下合并文本文件。但是,我只是在寻找以类似于git
描述“合并冲突”的方式专门呈现合并数据的东西。
有谁知道这样的实用程序?
先感谢您。
更新:根据 Ed Morton 的以下问题,这是两个测试文件的内容......
==== 文件.1 ====
common line 1 ...
common line 2 ...
common line 3 ...
something unique from file.1
a second line of something unique from file.1
common line 4 ...
common line 5 ...
something unique from file.1
common line 6 ...
common line 7 ...
==== 文件.2 ====
common line 1 ...
common line 2 ...
common line 3 ...
something unique from file.2
common line 4 ...
common line 5 ...
something unique from file.2
a second line of something unique from file.2
common line 6 ...
common line 7 ...
我用
diff -y <file1> <file2>
或者
sdiff <file1> <file2>
但我找不到如何从默认值更改标记:
<
>
|
特别是,我想添加一个可见的相等标记(默认一个是空格)替换它(例如):
=
实现类似:
ab c | ab d
efg = efg
试图快速阅读https://git.savannah.gnu.org/cgit/diffutils.git/tree/src/上的代码,但没有找到负责标记的位置(列分隔符)。
这可能已经回答了,但很难搜索——基本上,
当patch
发现一个block/hunk 无法申请时,它会将更改的hunk 拒绝到reject 文件中。
如何不将冲突放入拒绝文件但包含在最终输出中,就像找到git
冲突并将两个版本都包含在最终输出中一样:
$ cat merge.txt
<<<<<<< HEAD
this is some content to mess with
content to append
=======
totally different content to merge later
>>>>>>> new_branch_to_merge_later
我从 diff 得到以下结果:
@@ -4479,7 +4479,7 @@
|| AddPrintCheckParameters(TRUE)
|| AddRecipeDefaults(TRUE)
|| AddRepeatScanPass(TRUE)
- || AddVirgoFlag(TRUE)
+ || AddVirgoFlag(TRUE)
|| AddAttrPatchSize(TRUE)
|| AddDualSensParameters(TRUE)
|| AddMDATDensitySP(TRUE)
似乎它建议我删除并添加同一行。为什么?