使用 sed 替换 <?用 <?php [英] Using sed to replace <? with <?php

查看:56
本文介绍了使用 sed 替换 <?用 <?php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在一堆文件中以编程方式用 <?php 替换 <? ,但我的 sed 正则表达式的行为不像我预期的那样.你能告诉我它有什么问题吗?

I'm trying to programmatically replace <? with <?php in a bunch of file, but my sed regex isn't behaving like I expected. Can you tell me what's wrong with it?

我正在这里的命令行上测试它:

I'm testing it on the command line here:

$ sed -e 's/<\?/<\?php/g'
<?
<?php?<?php
d
<?phpd<?php

推荐答案

我认为你不需要转义符 ?:

I don't think you need the escapes on the ?:

sed -e 's/<?/<?php/g'

这篇关于使用 sed 替换 &lt;?用 &lt;?php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆