Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

sed + remove comments lines that include match string

the following sed command should delete the comment/s lines in file – /opt/presto/presto.conf

sed '/^[[:blank:]]*#/d' /opt/presto/presto.conf

in our case we want to delete the comment lines with AND case , means to delete the comment/s lines that also include the string – NOTE

example

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

more /opt/presto/presto.conf
#  task.max-worker-threads=16
#jmx.rmiregistry.port=8091
#    jmx.rmiserver.port=8092     /NOTE/

expected output

#  task.max-worker-threads=16
#jmx.rmiregistry.port=8091

we try with:

 sed '/NOTE/d ; /^[[:blank:]]*#/d'  /opt/presto/presto.conf`

but this above sed command delete the lines with NOTE and also the comments lines

>Solution :

This sed should work for you. Here we search for comment marker # at the line start followed by NOTE anywhere in the line:

sed '/^[[:blank:]]*#.*NOTE/d' file

#  task.max-worker-threads=16
#jmx.rmiregistry.port=8091

Or this one:

sed '/NOTE/ {/^[[:blank:]]*#/d;}' file
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading