Vivekanand S V
Vivekanand S V

Reputation: 2363

Is there any way to redirect part of output to a file?

From the whole output I want to redirect everything between 2 given patterns (or lines)

An example scenario will be, I have a log file and I just want to see the logs printed after a specific pattern until another specific pattern is matched.

Anyone know any way for this to achieve using terminal commands ?

Upvotes: 1

Views: 61

Answers (2)

Maroun
Maroun

Reputation: 95998

You can use grep, sed (or any other command that can use a regex) and use > to redirect:

grep ... > file

Upvotes: 0

pynexj
pynexj

Reputation: 20768

Does /the/command | sed -n '/pattern1/,/pattern2/p' > /some/file work for you?

Upvotes: 5

Related Questions