186k views
4 votes
Write a sed command that will display all lines of the birthday file that do not contain the string March. What was the sed command?

1 Answer

6 votes

Answer:

sed '/march/{d;}' birthdays.txt > result .txt

Step-by-step explanation:

sed syntax is basically:

sed '/expression/{command;command;...;}' inputfile > outputfile

  • First, for the expression part, we use /march/ to match all lines containing that string.
  • Then for the command part, we only use {d} command to delete every matching line found.
  • The third part contains the input file to process, I have named it birthdays.txt, but it could have been any other file needed.
  • Finally "> result .txt" makes the script output to be saved into a file named result.txt
User Shanky Singh
by
4.9k points