grep --before-context 5 shows 5 lines before the match.
I want to show everything before the match.
Doing grep --before-context 99999999 would work but it is not very... professional.
How to show all the file up to the match?
|
I want to show everything before the match. How to show all the file up to the match? |
|||
|
|
|
This means print from the first line until pattern is matched. A couple of range examples
|
|||||||
|
|
Sed is better for that. Just do:
It works like this: For each line, we look if it matches
This is the most efficient solution, because as soon as it sees This trick can also be used to emulate
|
|||||||
|
|
print up to and including the match:
print up to BUT NOT including the match:
Disclaimer: I know awk better than sed -- I bet there is a sed way to do both. |
|||
|
|
|
For people like me, who choose to remember only the basic usage of tools, and willing to accept less elegant and less efficient solutions:
|
|||||||||
|