gpt4 book ai didi

linux - 在 SED linux 中查找和替换值

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:42:59 25 4
gpt4 key购买 nike

我有一个名为 form.php 的文件:

<?php
sleep(10);
?>

目的是用sed执行这样的shell脚本:

$sh example.sh form.php 50

获取:

<?php
sleep(50);
?>

我试过了

$cat example.sh
#!/bin/sh
file=$1
sed -i "s/^\( *sleep\)\([^>]*\)</\1$2</" "$1"

但是不工作...

最佳答案

您可以使用:

sed "s/sleep([^)]*)/sleep($2)/" "$file"

或者这个:

sed "s/\(sleep\)([^)]*)/\1($2)/" "$file"

sed 默认使用 BRE,( or ) 将其作为文字而不是特殊的正则表达式元字符。

关于linux - 在 SED linux 中查找和替换值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40654477/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com