Only print output after finding pattern












1















There's a script (let's call it echoer) that prints to screen a bunch of information. I'd like to be able to only see lines after a pattern is found.



I imagine the usage of a solution to look something like



echoer | solution_command <pattern>


Ideally pattern would be a regular expression, but hard value strings would be enough for me.










share|improve this question









New contributor




user23146 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • So pattern can be multiple strings?

    – Inian
    1 hour ago











  • A glob? Do you mean a regular expression? Globs only make sense for file name expansions.

    – terdon
    55 mins ago











  • @Inian I'm not sure I understand the question. Do you mean to ask if I want this to work with disjunctions?

    – user23146
    39 mins ago
















1















There's a script (let's call it echoer) that prints to screen a bunch of information. I'd like to be able to only see lines after a pattern is found.



I imagine the usage of a solution to look something like



echoer | solution_command <pattern>


Ideally pattern would be a regular expression, but hard value strings would be enough for me.










share|improve this question









New contributor




user23146 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • So pattern can be multiple strings?

    – Inian
    1 hour ago











  • A glob? Do you mean a regular expression? Globs only make sense for file name expansions.

    – terdon
    55 mins ago











  • @Inian I'm not sure I understand the question. Do you mean to ask if I want this to work with disjunctions?

    – user23146
    39 mins ago














1












1








1








There's a script (let's call it echoer) that prints to screen a bunch of information. I'd like to be able to only see lines after a pattern is found.



I imagine the usage of a solution to look something like



echoer | solution_command <pattern>


Ideally pattern would be a regular expression, but hard value strings would be enough for me.










share|improve this question









New contributor




user23146 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












There's a script (let's call it echoer) that prints to screen a bunch of information. I'd like to be able to only see lines after a pattern is found.



I imagine the usage of a solution to look something like



echoer | solution_command <pattern>


Ideally pattern would be a regular expression, but hard value strings would be enough for me.







echo printf






share|improve this question









New contributor




user23146 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




user23146 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 40 mins ago







user23146













New contributor




user23146 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 1 hour ago









user23146user23146

83




83




New contributor




user23146 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





user23146 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






user23146 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.













  • So pattern can be multiple strings?

    – Inian
    1 hour ago











  • A glob? Do you mean a regular expression? Globs only make sense for file name expansions.

    – terdon
    55 mins ago











  • @Inian I'm not sure I understand the question. Do you mean to ask if I want this to work with disjunctions?

    – user23146
    39 mins ago



















  • So pattern can be multiple strings?

    – Inian
    1 hour ago











  • A glob? Do you mean a regular expression? Globs only make sense for file name expansions.

    – terdon
    55 mins ago











  • @Inian I'm not sure I understand the question. Do you mean to ask if I want this to work with disjunctions?

    – user23146
    39 mins ago

















So pattern can be multiple strings?

– Inian
1 hour ago





So pattern can be multiple strings?

– Inian
1 hour ago













A glob? Do you mean a regular expression? Globs only make sense for file name expansions.

– terdon
55 mins ago





A glob? Do you mean a regular expression? Globs only make sense for file name expansions.

– terdon
55 mins ago













@Inian I'm not sure I understand the question. Do you mean to ask if I want this to work with disjunctions?

– user23146
39 mins ago





@Inian I'm not sure I understand the question. Do you mean to ask if I want this to work with disjunctions?

– user23146
39 mins ago










1 Answer
1






active

oldest

votes


















5














AWK can do this with pattern ranges, which allows the use of any regular expression:



echoer | awk '/pattern/,0'


will print echoer’s output starting with the first line matching pattern.



AWK is pattern-based, and is typically used with a “if this pattern matches, do this” type of approach. “This pattern” can be a range of patterns, defined as “when this pattern matches, start going this, until this other pattern matches”; this is specified by writing two patterns separated by a comma, as above. Patterns can be text matches, as in /pattern/, where the current line is checked against the pattern, interpreted as a regular expression; they can also be general expressions, evaluated for every line, and considered to match if their result is non-zero or non-empty.



In AWK, the default action is to print the current line.



Putting all this together, awk '/pattern/,0' looks for lines matching pattern, and once it finds one, applies the default action to all lines until the 0 condition matches (is non-zero). awk '/pattern/,""' would work too.



The Gawk manual goes into much more detail.






share|improve this answer


























  • Thanks. This works. Any chance you can breakdown the syntax for those who don't know AWK? I know AWK operates line by line and it is triggered by matching the input pattern, but that's about it.

    – user23146
    36 mins ago






  • 1





    I was not aware of the range semantics with zero as the end of the range. Thanks!

    – Kusalananda
    36 mins ago











  • @user23146 I’ve tried to explain a bit better.

    – Stephen Kitt
    15 mins ago











  • @StephenKitt This is great! What if I wanted to print until it matched 0? Would it be /pattern/,/0/? What would the answer look like explicitly writing out the default action?

    – user23146
    10 mins ago











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






user23146 is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f509173%2fonly-print-output-after-finding-pattern%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









5














AWK can do this with pattern ranges, which allows the use of any regular expression:



echoer | awk '/pattern/,0'


will print echoer’s output starting with the first line matching pattern.



AWK is pattern-based, and is typically used with a “if this pattern matches, do this” type of approach. “This pattern” can be a range of patterns, defined as “when this pattern matches, start going this, until this other pattern matches”; this is specified by writing two patterns separated by a comma, as above. Patterns can be text matches, as in /pattern/, where the current line is checked against the pattern, interpreted as a regular expression; they can also be general expressions, evaluated for every line, and considered to match if their result is non-zero or non-empty.



In AWK, the default action is to print the current line.



Putting all this together, awk '/pattern/,0' looks for lines matching pattern, and once it finds one, applies the default action to all lines until the 0 condition matches (is non-zero). awk '/pattern/,""' would work too.



The Gawk manual goes into much more detail.






share|improve this answer


























  • Thanks. This works. Any chance you can breakdown the syntax for those who don't know AWK? I know AWK operates line by line and it is triggered by matching the input pattern, but that's about it.

    – user23146
    36 mins ago






  • 1





    I was not aware of the range semantics with zero as the end of the range. Thanks!

    – Kusalananda
    36 mins ago











  • @user23146 I’ve tried to explain a bit better.

    – Stephen Kitt
    15 mins ago











  • @StephenKitt This is great! What if I wanted to print until it matched 0? Would it be /pattern/,/0/? What would the answer look like explicitly writing out the default action?

    – user23146
    10 mins ago
















5














AWK can do this with pattern ranges, which allows the use of any regular expression:



echoer | awk '/pattern/,0'


will print echoer’s output starting with the first line matching pattern.



AWK is pattern-based, and is typically used with a “if this pattern matches, do this” type of approach. “This pattern” can be a range of patterns, defined as “when this pattern matches, start going this, until this other pattern matches”; this is specified by writing two patterns separated by a comma, as above. Patterns can be text matches, as in /pattern/, where the current line is checked against the pattern, interpreted as a regular expression; they can also be general expressions, evaluated for every line, and considered to match if their result is non-zero or non-empty.



In AWK, the default action is to print the current line.



Putting all this together, awk '/pattern/,0' looks for lines matching pattern, and once it finds one, applies the default action to all lines until the 0 condition matches (is non-zero). awk '/pattern/,""' would work too.



The Gawk manual goes into much more detail.






share|improve this answer


























  • Thanks. This works. Any chance you can breakdown the syntax for those who don't know AWK? I know AWK operates line by line and it is triggered by matching the input pattern, but that's about it.

    – user23146
    36 mins ago






  • 1





    I was not aware of the range semantics with zero as the end of the range. Thanks!

    – Kusalananda
    36 mins ago











  • @user23146 I’ve tried to explain a bit better.

    – Stephen Kitt
    15 mins ago











  • @StephenKitt This is great! What if I wanted to print until it matched 0? Would it be /pattern/,/0/? What would the answer look like explicitly writing out the default action?

    – user23146
    10 mins ago














5












5








5







AWK can do this with pattern ranges, which allows the use of any regular expression:



echoer | awk '/pattern/,0'


will print echoer’s output starting with the first line matching pattern.



AWK is pattern-based, and is typically used with a “if this pattern matches, do this” type of approach. “This pattern” can be a range of patterns, defined as “when this pattern matches, start going this, until this other pattern matches”; this is specified by writing two patterns separated by a comma, as above. Patterns can be text matches, as in /pattern/, where the current line is checked against the pattern, interpreted as a regular expression; they can also be general expressions, evaluated for every line, and considered to match if their result is non-zero or non-empty.



In AWK, the default action is to print the current line.



Putting all this together, awk '/pattern/,0' looks for lines matching pattern, and once it finds one, applies the default action to all lines until the 0 condition matches (is non-zero). awk '/pattern/,""' would work too.



The Gawk manual goes into much more detail.






share|improve this answer















AWK can do this with pattern ranges, which allows the use of any regular expression:



echoer | awk '/pattern/,0'


will print echoer’s output starting with the first line matching pattern.



AWK is pattern-based, and is typically used with a “if this pattern matches, do this” type of approach. “This pattern” can be a range of patterns, defined as “when this pattern matches, start going this, until this other pattern matches”; this is specified by writing two patterns separated by a comma, as above. Patterns can be text matches, as in /pattern/, where the current line is checked against the pattern, interpreted as a regular expression; they can also be general expressions, evaluated for every line, and considered to match if their result is non-zero or non-empty.



In AWK, the default action is to print the current line.



Putting all this together, awk '/pattern/,0' looks for lines matching pattern, and once it finds one, applies the default action to all lines until the 0 condition matches (is non-zero). awk '/pattern/,""' would work too.



The Gawk manual goes into much more detail.







share|improve this answer














share|improve this answer



share|improve this answer








edited 15 mins ago

























answered 56 mins ago









Stephen KittStephen Kitt

178k24405482




178k24405482













  • Thanks. This works. Any chance you can breakdown the syntax for those who don't know AWK? I know AWK operates line by line and it is triggered by matching the input pattern, but that's about it.

    – user23146
    36 mins ago






  • 1





    I was not aware of the range semantics with zero as the end of the range. Thanks!

    – Kusalananda
    36 mins ago











  • @user23146 I’ve tried to explain a bit better.

    – Stephen Kitt
    15 mins ago











  • @StephenKitt This is great! What if I wanted to print until it matched 0? Would it be /pattern/,/0/? What would the answer look like explicitly writing out the default action?

    – user23146
    10 mins ago



















  • Thanks. This works. Any chance you can breakdown the syntax for those who don't know AWK? I know AWK operates line by line and it is triggered by matching the input pattern, but that's about it.

    – user23146
    36 mins ago






  • 1





    I was not aware of the range semantics with zero as the end of the range. Thanks!

    – Kusalananda
    36 mins ago











  • @user23146 I’ve tried to explain a bit better.

    – Stephen Kitt
    15 mins ago











  • @StephenKitt This is great! What if I wanted to print until it matched 0? Would it be /pattern/,/0/? What would the answer look like explicitly writing out the default action?

    – user23146
    10 mins ago

















Thanks. This works. Any chance you can breakdown the syntax for those who don't know AWK? I know AWK operates line by line and it is triggered by matching the input pattern, but that's about it.

– user23146
36 mins ago





Thanks. This works. Any chance you can breakdown the syntax for those who don't know AWK? I know AWK operates line by line and it is triggered by matching the input pattern, but that's about it.

– user23146
36 mins ago




1




1





I was not aware of the range semantics with zero as the end of the range. Thanks!

– Kusalananda
36 mins ago





I was not aware of the range semantics with zero as the end of the range. Thanks!

– Kusalananda
36 mins ago













@user23146 I’ve tried to explain a bit better.

– Stephen Kitt
15 mins ago





@user23146 I’ve tried to explain a bit better.

– Stephen Kitt
15 mins ago













@StephenKitt This is great! What if I wanted to print until it matched 0? Would it be /pattern/,/0/? What would the answer look like explicitly writing out the default action?

– user23146
10 mins ago





@StephenKitt This is great! What if I wanted to print until it matched 0? Would it be /pattern/,/0/? What would the answer look like explicitly writing out the default action?

– user23146
10 mins ago










user23146 is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















user23146 is a new contributor. Be nice, and check out our Code of Conduct.













user23146 is a new contributor. Be nice, and check out our Code of Conduct.












user23146 is a new contributor. Be nice, and check out our Code of Conduct.
















Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f509173%2fonly-print-output-after-finding-pattern%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

He _____ here since 1970 . Answer needed [closed]What does “since he was so high” mean?Meaning of “catch birds for”?How do I ensure “since” takes the meaning I want?“Who cares here” meaningWhat does “right round toward” mean?the time tense (had now been detected)What does the phrase “ring around the roses” mean here?Correct usage of “visited upon”Meaning of “foiled rail sabotage bid”It was the third time I had gone to Rome or It is the third time I had been to Rome

Bunad

Færeyskur hestur Heimild | Tengill | Tilvísanir | LeiðsagnarvalRossið - síða um færeyska hrossið á færeyskuGott ár hjá færeyska hestinum