View Full Version : [ubuntu] What does this "sed" command do?

November 15th, 2011, 10:09 AM
I am trying to understand what this command does. It looks like, it extracts something (/usr/prog1/bin) from the PATH and appends it to /etc/environment . Please let me know if this is right:

sudo sed -i 's/\(PATH=\"\)/\1\/usr\/prog1\/bin:/' /etc/environment


crazy bird
November 15th, 2011, 10:20 AM
You can find the answer here:

If you want to learn more about Linux commands, just use google and type "linux commands":
http://www.google.nl/search?q=linux+command&hl=nl&source=hp&gs_sm=e&gs_upl=1469l4672l0l7031l16l14l0l2l2l0l297l2111l2.5 .5l12l0&oq=linux+command&aq=f&aqi=g10&aql=

Everything you want to know is available on the internet.

November 15th, 2011, 10:30 AM
replace (s///) in place -i (as in 'modify file', sed by default only prints out to terminal)
PATH= -> PATH=/usr/prog1/bin:
(PATH=) in parentheses is a selection group - it means that you can get that 'PATH=' with \1 in the replacement. If there are more () you go in order \1 \2 \3...

btw why the hell people do all that escaping -_-
-r removes the need for that in case of ()[] etc and you can use different separator than / (any symbol put after s will be used to separate the parts)

$ echo PATH=$PATH
$ echo PATH=$PATH | sed -r 's_(PATH=)_\1/what/ever:_'