首先用sed找到`protect和`endprotect的行。
sed -n '/\x60protect/p' xxx.v
sed -n '/\x60endprotect/p' xxx.v
再对找到的行行头加注释,
sed '/\x60protect/s/^/\/\//' xxx.v
sed '/\x60endprotect/s/^/\/\//' xxx.v
再用find | xargs
把所有的verilog文件找出来,并分别调用sed,确认效果。
find ../../rtl -name "*.v" | xargs -I {} sed '/\x60protect/s/^/\/\//' {}
find ../../rtl -name "*.v" | xargs -I {} sed '/\x60endprotect/s/^/\/\//' {}
最后,如果效果无误,就可以给sed加上-i
参数,让修改生效。
find ../../rtl -name "*.v" | xargs -I {} sed -i '/\x60protect/s/^/\/\//' {}
find ../../rtl -name "*.v" | xargs -I {} sed -i '/\x60endprotect/s/^/\/\//' {}
如果想要一条sed正则来实现也是可以的,可以用(|)
,但sed要加-E
来扩展正则语法。
find ../../rtl -name "*.v" | xargs -I {} sed -i -E '/\x60(protect|endprotect)/s/^/\/\//' {}