views:

574

answers:

3

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 me out?

+1  A: 

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.

EBGreen
+7  A: 

@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...

Blair Conrad
+13  A: 

Depending on the shell you are using, you can turn the approach @Blair suggested into a 1-liner

diff <(cut -b13- file1) <(cut -b13- file2)

(+1 to @Blair for the original suggestion :-)

toolkit