how can i replace one line in a multiple file on linux?

You may use this sed:

s='"tree": "/a/anything-here/b/"'
sed -E 's~"(/[^/]*/)[^/]*/~\1new-string/~' <<< "$s"
"tree": /a/new-string/b/"

Or using awk:

awk -v str='new-string' 'BEGIN{FS=OFS="/"} {$3 = str} 1' <<< "$s"
"tree": "/a/new-string/b/"

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top