An easy way to diff log files, ignoring the time stamps?

后端 未结 5 1744
终归单人心
终归单人心 2021-02-01 13:41

I need to diff two log files but ignore the time stamp part of each line (the first 12 characters to be exact). Is there a good tool, or a clever awk command, that could help m

5条回答
  •  梦谈多话
    2021-02-01 14:04

    @EbGreen said

    I would just take the log files and strip the timestamps off the start of each line then save the file out to different files. Then diff those files.

    That's probably the best bet, unless your diffing tool has special powers. For example, you could

    cut -b13- file1 > trimmed_file1
    cut -b13- file2 > trimmed_file2
    diff trimmed_file1 trimmed_file2
    

    See @toolkit's response for an optimization that makes this a one-liner and obviates the need for extra files. If your shell supports it. Bash 3.2.39 at least seems to...

提交回复
热议问题