AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题

问题[diff](unix)

Martin Hope
desert_ranger
Asked: 2024-03-16 03:09:58 +0800 CST

在比较文件夹的不同版本时,如何防止“diff -rq”显示新创建的文件?

  • 5

我正在检查两个文件夹(和)diff -rq之间的差异。我不想知道文件夹是否有任何新文件,因为这是预期的。我如何确保这些信息不会出现?ABA

diff
  • 1 个回答
  • 24 Views
Martin Hope
pmor
Asked: 2023-05-12 19:24:49 +0800 CST

为什么来自进程替换的输入的 diff3 发现差异,而文件中相同数据的 diff3 没有发现差异?

  • 8

文件上的 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
diff
  • 1 个回答
  • 69 Views
Martin Hope
Sollosa
Asked: 2023-05-08 16:32:39 +0800 CST

ansible比较2个目录中的所有文件并打印差异

  • 6

我有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"
}
diff
  • 1 个回答
  • 29 Views
Martin Hope
vishvAs vAsuki
Asked: 2022-09-28 09:42:48 +0800 CST

很好地区分两个目录

  • 0

我需要区分(并合并)两个目录(实际上是相同的内容,在一组文件中插入了一些额外的行)。唉,我尝试过的所有差异程序(kompare、diffmerge、kdiff3、diffuse、xxdiff、)都不能很好地显示差异(来自 intellij idea 的屏幕截图);或仅限于差异文件(在这种情况下,我没有检查它们是否做得更好)。这两个目录是:A和B。

你能推荐一个好的 diff 程序来解决这个问题(强烈推荐 GUI,必须免费使用)?

差异失败截图

diff merge
  • 1 个回答
  • 42 Views
Martin Hope
Dimitrios Desyllas
Asked: 2022-09-23 05:37:45 +0800 CST

如何使用 diff 从 a.txt 文件中获取缺失的行?

  • 0

我有以下文件:

一个.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

仅有的。有没有办法在差异上放置某种过滤器?

diff
  • 2 个回答
  • 23 Views
Martin Hope
HippoMan
Asked: 2022-09-18 16:42:28 +0800 CST

合并两个非基于 git 的文本文件,语义相似,描述 git 合并冲突

  • 3

我想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 ...
text-processing diff
  • 3 个回答
  • 48 Views
Martin Hope
Olaf
Asked: 2022-06-22 00:49:52 +0800 CST

仅递归列出文件的路径

  • 1

为什么

我有两个文件夹应该包含完全相同的文件,但是,当我查看文件数量时,它们是不同的。我想知道一个文件/文件夹中存在哪些文件/文件夹,而不是另一个。我的想法是我将列出所有文件,然后使用 comm 查找两个文件夹之间的差异。

问题

如何以 /path/to/dir 和 /path/to/dir/file 格式递归地列出文件和文件夹?

重要笔记

操作系统:Windows 11,子系统 Ubuntu 20.04.4 LTS

位置文件夹:一个网络驱动器,一个本地驱动器

文件夹大小:每个~2tb

find diff
  • 3 个回答
  • 59 Views
Martin Hope
Alexander Ites
Asked: 2022-06-17 04:37:36 +0800 CST

如何将差异并排标记更改为其他标记?

  • 1

我用

diff -y <file1> <file2>

或者

sdiff <file1> <file2>

但我找不到如何从默认值更改标记:

<
>
|

特别是,我想添加一个可见的相等标记(默认一个是空格)替换它(例如):

=

实现类似:

ab c  | ab d
efg   = efg

试图快速阅读https://git.savannah.gnu.org/cgit/diffutils.git/tree/src/上的代码,但没有找到负责标记的位置(列分隔符)。

diff sdiff
  • 1 个回答
  • 19 Views
Martin Hope
xpt
Asked: 2022-06-07 10:54:48 +0800 CST

没有拒绝的补丁

  • 0

这可能已经回答了,但很难搜索——基本上,

当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 patch
  • 1 个回答
  • 59 Views
Martin Hope
Ziqi Fan
Asked: 2022-05-14 16:06:32 +0800 CST

来自差异的令人困惑的结果

  • 0

我从 diff 得到以下结果:

@@ -4479,7 +4479,7 @@
         || AddPrintCheckParameters(TRUE)
         || AddRecipeDefaults(TRUE)
         || AddRepeatScanPass(TRUE)
-        || AddVirgoFlag(TRUE)        
+        || AddVirgoFlag(TRUE)
         || AddAttrPatchSize(TRUE)
         || AddDualSensParameters(TRUE)
         || AddMDATDensitySP(TRUE)

似乎它建议我删除并添加同一行。为什么?

diff
  • 1 个回答
  • 27 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve