使用 shell 命令比较两个文件,除了每行的第一个字节
我有两个日志文件,每一行都从时间开始。我想比较除了这个时间部分之外的文件。
例如:
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
选项,但对于每一行
我不不知道该怎么做,我读过diff
和 cmp
的人,也许我错过了一些东西,但它似乎不是一个现有的选项?
另一方面,我不知道如何在比较之前使用某些 sed
或 awk
操作来修改文件,因为 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您可以处理 Bash,则可以使用进程替换:
If you can handle Bash, you could use process substitution: