-2

HI 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
----------------------------------------------------------

Please suggest...

anubhava
  • 713,503
  • 59
  • 514
  • 593
dhandma
  • 67
  • 7
  • Please avoid *"Give me the codez"* questions. Also see [How much research effort is expected of Stack Overflow users?](https://meta.stackoverflow.com/q/261592/608639) – jww Jun 28 '18 at 11:16

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/