php - 相当于 PHP 的 preg_replace() 的 Shell

标签 php regex bash preg-replace unix

大家好。

我正在寻找一种方法来做与 PHP 的 preg_replace() 相同的事情在 shell 脚本中执行(搜索与正则表达式匹配的文本并替换它)。

因此,请考虑以下文件。

<a href="http://example.com/">Website #1</a>
<a href="http://example.net/">Website #2</a>
<a href="http://example.org/">Website #3</a>

我想得到这个:

http://example.com/
http://example.net/
http://example.org/

有没有办法做到这一点?谢谢。

最佳答案

您可以将 sed 用作:

sed -r 's/.*href="([^"]*)".*/\1/' file

See it

关于php - 相当于 PHP 的 preg_replace() 的 Shell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4490927/

相关文章:

php - 加快图像转换时间

python - 优化 - 匹配数据框列中的单词序列

bash - 使用bash从文件中提取文本

linux - Bash 输出最高值的行

bash - ssh,nohup,然后将结果复制回去

javascript - 如何在开发人员模式浏览器(检查)中将数据发送到服务器而不显示它?

php - 使用 phpExcel 库将新行附加到 excel 文件

php - 在 cookie header 之前或之后发送 HTTP header ?

Mysql使用高级正则表达式选择数据

regex - 正则表达式,我可以排除字符对吗?