-2

I want to remove line from file have below lines starting with # and have Apache/apache. Please find below file content which I want to manipulate and remove :

----------------------------------------------------------
# Apache configuration
# This is apache configuration
This is not Apache configuration
----------------------------------------------------------
Dharman
  • 30,962
  • 25
  • 85
  • 135
dhandma
  • 77
  • 1
  • 9

1 Answers1

-1

You could do this using Regex and sed.

This should do it:

sed -i '/^#.*[Aa]pache/ d' <filename>

Broken down it is:

  • -i: Read file, make changes and write result back to file
  • ^#: Line starting with #
  • .*: Any number of characters in between
  • [Aa]: Match both upper and lower case A/a
  • pache: Match the rest of the word
  • / d: delete any lines that match
  • filename: file to edit in place

If you need the output to go to stdout, you could also do:

cat <filename> | sed '/^#.*[Aa]pache/ d' 

I'd recommend learning to use regular expressions: https://regexone.com/