0

I am trying to replace charater < with empty or no charaeter in this file /etc/dovecot/conf.d/10-ssl.conf

My script is

sudo sed -i 's/\<\/etc\/dovecot\/private\/dovecot\.pem/\/etc\/dovecot\/private\/dovecot\.pem/g' /etc/dovecot/conf.d/10-ssl.conf 

It didn't work then tired:-

sudo sed -i '0,/\<\/etc\/dovecot\/private\/dovecot\.pem/s/\<\/etc\/dovecot\/private\/dovecot\.pem/\/etc\/dovecot\/private\/dovecot\.pem/' /etc/dovecot/conf.d/10-ssl.conf 

It didn't work as well. What is wrong and how can I do it? Also, it is long. How can I split it multiple lines?

4

In sed, \< matches "beginning of a word", while plain < matches literally.

For a more readable substitution, change the delimiters:

sed -i 's=</etc/dovecot/private/dovecot\.pem=/etc/dovecot/private/dovecot.pem=g'

There's no need to backslash dots in the replacement part.

You can further shorten the instruction by using a capture:

sed -i 's=<\(/etc/dovecot/private/dovecot\.pem\)=\1=g'
  • Wonderful it workes. Perhaps the capture totally new to me. Could you please describe how it works? I am sure ur explanation will help others as well. – masiboo May 22 at 15:59
  • 1
    Each part between \(..\) is captured. The \1 refers to the first capture (yes, you can have more than one). – choroba May 22 at 16:20
  • Strange enough same script works fine in the local Ubuntu. But it is not working in AWS EC2. Same version of Ubuntu running there. Of couser, I am running as with sudo – masiboo May 22 at 16:21
  • How do you run the script in AWS? – choroba May 22 at 16:28
  • I am making a script for AWS ec2 instance. This should setup postfix in AWS. That is why – masiboo May 22 at 16:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.