使用 shell 命令比较两个文件,除了每行的第一个字节

发布于 2025-01-14 03:45:12 字数 678 浏览 3 评论 0原文

我有两个日志文件,每一行都从时间开始。我想比较除了这个时间部分之外的文件。

例如:

file1.og

[20220201_133108] abc
[20220201_133108] defg
[20220201_133108] hi
[20220201_133108] jkl

file2.og

[20220202_172431] abc
[20220202_172431] defg
[20220202_172431] hi
[20220202_172431] jkl

它们是相同的,除了时间部分,所以想使用类似 diff [跳过第一个字节的选项] file1.log file2.log 会输出它们是相同的,有点像 cmp-i 选项,但对于每一行

我不不知道该怎么做,我读过diffcmp 的人,也许我错过了一些东西,但它似乎不是一个现有的选项?

另一方面,我不知道如何在比较之前使用某些 sedawk 操作来修改文件,因为 diff 需要一个文件或目录,不是命令的输出?当然,除了创建临时文件,我希望这不是必需的

I have two log files with every line starting by the time. I'd like to compare the files except for this time part.

for exemple :

file1.og

[20220201_133108] abc
[20220201_133108] defg
[20220201_133108] hi
[20220201_133108] jkl

file2.og

[20220202_172431] abc
[20220202_172431] defg
[20220202_172431] hi
[20220202_172431] jkl

they are identical, except for the time part, so would like to use something like diff [option to skip first bytes] file1.log file2.log that would output that they are identical, a little bit like the -i option of cmp, but for each lines

I don't know how to do that, I've read the man of diff and cmp and maybe I missed something, but it doesn't seems like it's an existing option ?

In other hands, I don't see how I could use some sed or awk action to modify the file before comparing it, since diff is expecting a file, or a directory, not the output of a command ? Except of course to create temporary files, which I hope is not necessary

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

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

发布评论

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

评论(1

相思碎 2025-01-21 03:45:12

如果您可以处理 Bash,则可以使用进程替换

$ diff <(cut -d \  -f 2 file1) <(cut -d \  -f 2 file2)

If you can handle Bash, you could use process substitution:

$ diff <(cut -d \  -f 2 file1) <(cut -d \  -f 2 file2)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文