Show the previous and after N lines each for the matched lines?

Question:

The following command will show the lines match the pattern.

How to show the previous and after 3 lines each for the matched lines? (Like the -C3 parameter of grep.) Also is it possible to print out the line number?

BTW, the command is much slower comparing with grep?

Answer:

Specify the filename in the -Path parameter of Select-String, and use the -Context switch to specify the number of lines before and after to include.

The file name and line number will be included in the output

Source:

Show the previous and after N lines each for the matched lines? by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply