开发者

Comparing two files

开发者 https://www.devze.com 2022-12-18 14:18 出处:网络
Can anyone create a script for a file comparison? The pseudo code looks like this extract line 5 from file 1

Can anyone create a script for a file comparison?

The pseudo code looks like this

  • extract line 5 from file 1
  • save it in another variable,
  • extract line 5 from file 2,
  • save it in another variable,
  • if variable 开发者_运维知识库1 is not equal to variable 2 (while allowing for differing characters at positions 11 and 12 from the end of line)

    • then fail
    • else pass


Unix shell? Pass the fileneames as arguments to the following script:

#!/bin/sh
a="$(head -n 5 < $1|tail -n 1)"
b="$(head -n 5 < $2|tail -n 1)"
test "$a" = "$b" && (echo The same; exit 0)
echo Different; exit 1
0

精彩评论

暂无评论...
验证码 换一张
取 消