How to check if sed has changed a file

后端 未结 9 1303
难免孤独
难免孤独 2020-12-01 06:57

I am trying to find a clever way to figure out if the file passed to sed has been altered successfully or not.

Basically, I want to know if the file has been changed

9条回答
  •  时光取名叫无心
    2020-12-01 07:34

    In macos I just do it as follows:

    changes=""
    changes+=$(sed -i '' "s/$to_replace/$replacement/g w /dev/stdout" "$f")
    if [ "$changes" != "" ]; then
      echo "CHANGED!"
    fi
    

    I checked, and this is faster than md5, cksum and sha comparisons

提交回复
热议问题