Home > Enterprise >  what is meaning of sed -e 's|PATH="\(.*\)"|PATH="/opt/man/common/bin:\1"
what is meaning of sed -e 's|PATH="\(.*\)"|PATH="/opt/man/common/bin:\1"

Time:07-07

what is meaning of following command?

sed -e 's|PATH="\(.*\)"|PATH="/opt/man/common/bin:\1"|g' -i /etc/environment

CodePudding user response:

It substitutes all the instances of

PATH="somestring"

with

PATH="/opt/man/common/bin:somestring"

in the file /etc/environment

In detail

  • s|string1|string2| substitutes string1 with string2
    • the delimiter (in this case |) is defined by the character following the substitute command (s). More common is /.
    • the flag g at the end tells sed to substitute all non-overlapping matches (and not only the first one)
    • the \( and \) define a group (in this case everything between the quotes)
    • the \1 is a back-reference to the first group
  • -i is telling sed to apply the changes directly in the file (inline) instead of writing to standard output.
  • Related