简体   繁体   中英

Bash Diff ignore change on one line

I have two files, file1.txt and file2.txt, and i want to ignore the difference on the time value (time1 and time2). I tried to do diff -I "*TimeComparaison*" files1.txt files2.txt , but it doesn't work. Do you have any other solution?

file1.txt:

latitude {
  value: "150"
}
longitude {
  value: "-120"
}
time1 {
  value: "3580"
}
speed {
  value: "45"
}
time2 {
  value: "50589246"
}

And file2.txt:

latitude {
  value: "150"
}
longitude {
  value: "-120"
}
time1 {
  TimeComparaison
}
speed {
  value: "45"
}
time2 {
  TimeComparaison
}

Try using sed with process substitution to filter out things that you want diff to ignore. This can be useful for zeroing out timestamps and other noise.

diff <(sed -f 'normalize.sed' file1.txt) <(sed -f 'normalize.sed' file2.txt)

The normalize.sed script deletes time1 {} and time2 {} blocks:

/^time[12] {/, /^}/ d

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM