I am trying to use sed to replace a line with spaces with a defined variable.
For example,
I want to replace 'a dumb string' with $lan, and lan="~/afile.py
I assumed the line would be
sed "s/a dumb string/$lan/g" file.txt
but this leave the 'a dumb string' part blank in the file.txt.
My problem seems simple enough. Any help is much appreciated.
An even less-known fact is that you can use a different delimiter even for patterns used in addresses, using a special syntax: # do this (ugly)... sed '/\/a\/b\/c\//{do something;}' # ...or these (better) sed '\#/a/b/c/#{do something;}' sed '\_/a/b/c/_{do something;}' sed '\%/a/b/c/%{do something;}' # etc.
Since the text we are dealing with contains / , we're using % as an alternative delimiter in the sed expressions. This first removes the string . git (possibly followed by a / ) from the end of each line of input before applying the same substitution as in the first sed command.
Sometime space in search string does not work so needed to use [[:space:]] in centos.
sed -i 's/User[[:space:]]daemon/User apache/' httpd1.conf
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With