Jose Torres
Jose Torres

Reputation: 39

find and replace value in SED linux

i have a file called form.php:

<?php
sleep(10);
?>

The purpose is to execute a shell script like this with sed:

$sh example.sh form.php 50

For obtain:

<?php
sleep(50);
?>

I tried this

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

but dont work...

Upvotes: 1

Views: 73

Answers (1)

anubhava
anubhava

Reputation: 785126

You can use:

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

or this one:

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

sed use BRE by default and ( or ) take as literal not as special regex meta character.

Upvotes: 1

Related Questions