Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在一些 PHP 文件中,我想替换"?>\s\t\n\EOF". 我对此进行了测试,以搜索发生此问题的所有文件:
"?>\s\t\n\EOF"
ack "\?\>[\s\n\t]+\z"
我得到结果,但我只想替换它?>EOF。我用“sed”测试另一个命令:
?>EOF
sed 's/?>[\n\t\s]+\z/?>/'
你有什么建议吗?
例子 :
?>
ack 是基于 perl 的,而 sed 不能识别像 \z 这样的东西。使用 perl:
perl -pe 's/\?\>[\s\n\t]+\z/?>\n/'
此外,\z 不是 EOF,而只是字符串的结尾,因此 \z 将匹配每一行的结尾。如果您希望它仅在文件末尾匹配,则需要使用 \z 以外的其他内容。