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
CodePudding user response:
If you can handle Bash, you could use process substitution:
$ diff <(cut -d \ -f 2 file1) <(cut -d \ -f 2 file2)