是否有通配符来修补两个字符之间的任何字符序列?

Is there a wildcard to patch any sequence of characters between two characters?

我想修改一个更改文件校验和的补丁

-SRCREV = "a43570ced29f21cfbd5eff12b843f9214271aaf3"
+SRCREV = "somechecksum"

到别的地方。同时,补丁中的显式校验和在实际文件中发生了变化,hunk 失败了,我将不得不生成一个新补丁,这可能会有点麻烦。

那么有没有办法替换引号之间或整行之间的任何内容?

如果告诉diff使用ed样式输出,原文不会出现。但是,如果您尝试修补要更改的行已移动的文件,则不会有任何防止损坏的保护措施:

mkdir a b c t

cat <<'EOD' >a/test
1. a
2. b
3. c
4. d
5. e
EOD

cat <<'EOD' >b/test
1. a
2. b
3 <<< changed!
4. d
5. e
EOD

cat <<'EOD' >c/test
1. a
2. b
4. d
3. c
5. e
EOD

diff -u a/test b/test >patch1

cp a/test t/test
patch -p1 t/test <patch1
cat t/test  # identical to b/test

cp c/test t/test
patch -p1 t/test <patch1
cat t/test  # correct line is changed

diff -e a/test b/test >patch2

cp a/test t/test
patch -p1 t/test <patch2
cat t/test  # identical to b/test

cp c/test t/test
patch -p1 t/test <patch2
cat t/test  # wrong line is changed - result is broken

如果您不必使用 diff/patch,那么一个简单的 sed 脚本可能会起作用。类似于:

sed -i -e 's/^\(SRCREV = \)"[^"]*"/"somechecksum"/' fileToPatch