sed -n -E -e '/word/,$ p' filename.txt

More specific Questions:

Why is -e needed here? Does it serve any purpose in the example?

I know p is for print and $ indicates the end of the line but what does the compination ,$ p do exactly here?

  • In the context of an address range, $ means the last line of the file rather than the end of a line: see Addresses overview – steeldriver May 13 '17 at 16:50
  • I might recommend to have at hand any of the cheatsheets that can be found in the web. This URL searches for PDF's of them on Duckduckgo – XavierStuvw May 13 '17 at 17:46

/word/,$ is the address range for the p command.

/word/,$p will apply the p command (print) to all lines from the first that contains word anywhere on it, to the end of the file.

-e is not needed in this example as there is only one expression for sed to execute. You also do not need -E as the example is not making use of POSIX extended regular expressions.

  • -e tell sed to use next arg as command
  • /word/,$ select all line from the one having word to end of file.
  • p print

if you forget -n you will have whole file printed

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.