Only print output after finding patternHow to sed chunks text from a stream of files from findprint output to 3 separate columnsHow to print to the left and right of already printed outputprint characters repetitively using asterisk symbol in bashformat command output with variable and fixed spaceGet the output in a formatted wayHow to print $STR1 and $STR2 - not their contents - into a file?Print variable with backslashes in dashecho for Print outputBest way to create table-like CLI display in Bash?print a column with the desire format output
Can the number of solutions to a system of PDEs be bounded using the characteristic variety?
Rock identification in KY
Revoked SSL certificate
Mutually beneficial digestive system symbiotes
Why is 150k or 200k jobs considered good when there's 300k+ births a month?
Why does Kotter return in Welcome Back Kotter?
how to check a propriety using r studio
Are astronomers waiting to see something in an image from a gravitational lens that they've already seen in an adjacent image?
Replacing matching entries in one column of a file by another column from a different file
If human space travel is limited by the G force vulnerability, is there a way to counter G forces?
High voltage LED indicator 40-1000 VDC without additional power supply
How old can references or sources in a thesis be?
How is it possible to have an ability score that is less than 3?
Why can't we play rap on piano?
What's the point of deactivating Num Lock on login screens?
Theorems that impeded progress
Mortgage Pre-approval / Loan - Apply Alone or with Fiancée?
Question on branch cuts and branch points
What would happen to a modern skyscraper if it rains micro blackholes?
Do I have a twin with permutated remainders?
What is the word for reserving something for yourself before others do?
A case of the sniffles
Get value of a counter
Why doesn't a class having private constructor prevent inheriting from this class? How to control which classes can inherit from a certain base?
Only print output after finding pattern
How to sed chunks text from a stream of files from findprint output to 3 separate columnsHow to print to the left and right of already printed outputprint characters repetitively using asterisk symbol in bashformat command output with variable and fixed spaceGet the output in a formatted wayHow to print $STR1 and $STR2 - not their contents - into a file?Print variable with backslashes in dashecho for Print outputBest way to create table-like CLI display in Bash?print a column with the desire format output
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
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
add a comment |
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
So pattern can be multiple strings?
– Inian
Mar 28 at 9:41
A glob? Do you mean a regular expression? Globs only make sense for file name expansions.
– terdon♦
Mar 28 at 9:47
@Inian I'm not sure I understand the question. Do you mean to ask if I want this to work with disjunctions?
– user23146
Mar 28 at 10:03
add a comment |
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
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
echo printf
edited Mar 28 at 10:02
user23146
asked Mar 28 at 9:39
user23146user23146
684
684
So pattern can be multiple strings?
– Inian
Mar 28 at 9:41
A glob? Do you mean a regular expression? Globs only make sense for file name expansions.
– terdon♦
Mar 28 at 9:47
@Inian I'm not sure I understand the question. Do you mean to ask if I want this to work with disjunctions?
– user23146
Mar 28 at 10:03
add a comment |
So pattern can be multiple strings?
– Inian
Mar 28 at 9:41
A glob? Do you mean a regular expression? Globs only make sense for file name expansions.
– terdon♦
Mar 28 at 9:47
@Inian I'm not sure I understand the question. Do you mean to ask if I want this to work with disjunctions?
– user23146
Mar 28 at 10:03
So pattern can be multiple strings?
– Inian
Mar 28 at 9:41
So pattern can be multiple strings?
– Inian
Mar 28 at 9:41
A glob? Do you mean a regular expression? Globs only make sense for file name expansions.
– terdon♦
Mar 28 at 9:47
A glob? Do you mean a regular expression? Globs only make sense for file name expansions.
– terdon♦
Mar 28 at 9:47
@Inian I'm not sure I understand the question. Do you mean to ask if I want this to work with disjunctions?
– user23146
Mar 28 at 10:03
@Inian I'm not sure I understand the question. Do you mean to ask if I want this to work with disjunctions?
– user23146
Mar 28 at 10:03
add a comment |
6 Answers
6
active
oldest
votes
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 doing 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.
3
I was not aware of the range semantics with zero as the end of the range. Thanks!
– Kusalananda♦
Mar 28 at 10:06
@StephenKitt This is great! What if I wanted to print until it matched0
? Would it be/pattern/,/0/
? What would the answer look like explicitly writing out the default action?
– user23146
Mar 28 at 10:32
@user23146 yes,/pattern/,/0/
would print until it found a line (record) containing “0”. Writing the snippet in the answer with an explicit action gives/pattern/,0 print $0
, or equivalently/pattern/,0 print
.
– Stephen Kitt
Mar 28 at 10:46
add a comment |
The obligatory sed
equivalent of @StephenKitt's awk
one:
sed '/pattern/,$!d'
pattern
there is interpreted as a Basic Regular Expression like in grep
(as opposed to Extended Regular Expression in awk
/egrep
/grep -E
). Some sed
implementations have a -E
(BSD, ast, recent GNU/busybox, soon POSIX) or -r
(GNU, ssed, busybox, some recent BSD) option to make it Extended Regular Expressions instead and some have -P
(ast) or -R
(ssed) to make it a perl-like regular expression.
With perl
:
perl -ne 'print if /pattern/ .. undef'
add a comment |
with GNU and *BSD grep:
grep -A1000000000 pattern file
Unless your file has more than 1M lines, that's it.
add a comment |
If you're using a pager such as less
to view output from the command
less +pattern
add a comment |
awk
for lines after (but not including) the first pattern match
If the line containing the trigger pattern is the equivalent of "CUT HERE", you can omit it from the printed output:
echoer | awk 'flag ; /pattern/ flag=1 '
Each line of input runs through two components in the awk code. The first component is flag
, which awk interprets as "print the line if the variable flag
is nonzero". Since awk variables are 0 by default, this will initially not print anything.
The second component, /pattern/ flag=1
, sets the flag to 1 as soon as it detects the pattern, and the flag keeps that value for the rest of the run.
By the time that the pattern is first detected, the opportunity to print that line of input has passed. Any subsequent lines (including additional lines containing the pattern) will print.
add a comment |
Bash
A bit clunky, but it works.
#!/bin/bash
found=false
while IFS= read -r; do
if $found || [[ $REPLY =~ pattern ]]; then
found=true
printf '%sn' "$REPLY"
fi
done
This version relies on cat
, but it's easier to understand.
#!/bin/bash
while IFS= read -r; do
if [[ $REPLY =~ pattern ]]; then
printf '%sn' "$REPLY"
break
fi
done
cat
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
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 doing 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.
3
I was not aware of the range semantics with zero as the end of the range. Thanks!
– Kusalananda♦
Mar 28 at 10:06
@StephenKitt This is great! What if I wanted to print until it matched0
? Would it be/pattern/,/0/
? What would the answer look like explicitly writing out the default action?
– user23146
Mar 28 at 10:32
@user23146 yes,/pattern/,/0/
would print until it found a line (record) containing “0”. Writing the snippet in the answer with an explicit action gives/pattern/,0 print $0
, or equivalently/pattern/,0 print
.
– Stephen Kitt
Mar 28 at 10:46
add a comment |
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 doing 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.
3
I was not aware of the range semantics with zero as the end of the range. Thanks!
– Kusalananda♦
Mar 28 at 10:06
@StephenKitt This is great! What if I wanted to print until it matched0
? Would it be/pattern/,/0/
? What would the answer look like explicitly writing out the default action?
– user23146
Mar 28 at 10:32
@user23146 yes,/pattern/,/0/
would print until it found a line (record) containing “0”. Writing the snippet in the answer with an explicit action gives/pattern/,0 print $0
, or equivalently/pattern/,0 print
.
– Stephen Kitt
Mar 28 at 10:46
add a comment |
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 doing 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.
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 doing 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.
edited Mar 28 at 14:24
answered Mar 28 at 9:46
Stephen KittStephen Kitt
180k25408486
180k25408486
3
I was not aware of the range semantics with zero as the end of the range. Thanks!
– Kusalananda♦
Mar 28 at 10:06
@StephenKitt This is great! What if I wanted to print until it matched0
? Would it be/pattern/,/0/
? What would the answer look like explicitly writing out the default action?
– user23146
Mar 28 at 10:32
@user23146 yes,/pattern/,/0/
would print until it found a line (record) containing “0”. Writing the snippet in the answer with an explicit action gives/pattern/,0 print $0
, or equivalently/pattern/,0 print
.
– Stephen Kitt
Mar 28 at 10:46
add a comment |
3
I was not aware of the range semantics with zero as the end of the range. Thanks!
– Kusalananda♦
Mar 28 at 10:06
@StephenKitt This is great! What if I wanted to print until it matched0
? Would it be/pattern/,/0/
? What would the answer look like explicitly writing out the default action?
– user23146
Mar 28 at 10:32
@user23146 yes,/pattern/,/0/
would print until it found a line (record) containing “0”. Writing the snippet in the answer with an explicit action gives/pattern/,0 print $0
, or equivalently/pattern/,0 print
.
– Stephen Kitt
Mar 28 at 10:46
3
3
I was not aware of the range semantics with zero as the end of the range. Thanks!
– Kusalananda♦
Mar 28 at 10:06
I was not aware of the range semantics with zero as the end of the range. Thanks!
– Kusalananda♦
Mar 28 at 10:06
@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
Mar 28 at 10:32
@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
Mar 28 at 10:32
@user23146 yes,
/pattern/,/0/
would print until it found a line (record) containing “0”. Writing the snippet in the answer with an explicit action gives /pattern/,0 print $0
, or equivalently /pattern/,0 print
.– Stephen Kitt
Mar 28 at 10:46
@user23146 yes,
/pattern/,/0/
would print until it found a line (record) containing “0”. Writing the snippet in the answer with an explicit action gives /pattern/,0 print $0
, or equivalently /pattern/,0 print
.– Stephen Kitt
Mar 28 at 10:46
add a comment |
The obligatory sed
equivalent of @StephenKitt's awk
one:
sed '/pattern/,$!d'
pattern
there is interpreted as a Basic Regular Expression like in grep
(as opposed to Extended Regular Expression in awk
/egrep
/grep -E
). Some sed
implementations have a -E
(BSD, ast, recent GNU/busybox, soon POSIX) or -r
(GNU, ssed, busybox, some recent BSD) option to make it Extended Regular Expressions instead and some have -P
(ast) or -R
(ssed) to make it a perl-like regular expression.
With perl
:
perl -ne 'print if /pattern/ .. undef'
add a comment |
The obligatory sed
equivalent of @StephenKitt's awk
one:
sed '/pattern/,$!d'
pattern
there is interpreted as a Basic Regular Expression like in grep
(as opposed to Extended Regular Expression in awk
/egrep
/grep -E
). Some sed
implementations have a -E
(BSD, ast, recent GNU/busybox, soon POSIX) or -r
(GNU, ssed, busybox, some recent BSD) option to make it Extended Regular Expressions instead and some have -P
(ast) or -R
(ssed) to make it a perl-like regular expression.
With perl
:
perl -ne 'print if /pattern/ .. undef'
add a comment |
The obligatory sed
equivalent of @StephenKitt's awk
one:
sed '/pattern/,$!d'
pattern
there is interpreted as a Basic Regular Expression like in grep
(as opposed to Extended Regular Expression in awk
/egrep
/grep -E
). Some sed
implementations have a -E
(BSD, ast, recent GNU/busybox, soon POSIX) or -r
(GNU, ssed, busybox, some recent BSD) option to make it Extended Regular Expressions instead and some have -P
(ast) or -R
(ssed) to make it a perl-like regular expression.
With perl
:
perl -ne 'print if /pattern/ .. undef'
The obligatory sed
equivalent of @StephenKitt's awk
one:
sed '/pattern/,$!d'
pattern
there is interpreted as a Basic Regular Expression like in grep
(as opposed to Extended Regular Expression in awk
/egrep
/grep -E
). Some sed
implementations have a -E
(BSD, ast, recent GNU/busybox, soon POSIX) or -r
(GNU, ssed, busybox, some recent BSD) option to make it Extended Regular Expressions instead and some have -P
(ast) or -R
(ssed) to make it a perl-like regular expression.
With perl
:
perl -ne 'print if /pattern/ .. undef'
answered Mar 28 at 14:48
Stéphane ChazelasStéphane Chazelas
313k57592948
313k57592948
add a comment |
add a comment |
with GNU and *BSD grep:
grep -A1000000000 pattern file
Unless your file has more than 1M lines, that's it.
add a comment |
with GNU and *BSD grep:
grep -A1000000000 pattern file
Unless your file has more than 1M lines, that's it.
add a comment |
with GNU and *BSD grep:
grep -A1000000000 pattern file
Unless your file has more than 1M lines, that's it.
with GNU and *BSD grep:
grep -A1000000000 pattern file
Unless your file has more than 1M lines, that's it.
answered Mar 28 at 14:55
mosvymosvy
9,0571833
9,0571833
add a comment |
add a comment |
If you're using a pager such as less
to view output from the command
less +pattern
add a comment |
If you're using a pager such as less
to view output from the command
less +pattern
add a comment |
If you're using a pager such as less
to view output from the command
less +pattern
If you're using a pager such as less
to view output from the command
less +pattern
answered Mar 29 at 2:29
iruvariruvar
12.2k63062
12.2k63062
add a comment |
add a comment |
awk
for lines after (but not including) the first pattern match
If the line containing the trigger pattern is the equivalent of "CUT HERE", you can omit it from the printed output:
echoer | awk 'flag ; /pattern/ flag=1 '
Each line of input runs through two components in the awk code. The first component is flag
, which awk interprets as "print the line if the variable flag
is nonzero". Since awk variables are 0 by default, this will initially not print anything.
The second component, /pattern/ flag=1
, sets the flag to 1 as soon as it detects the pattern, and the flag keeps that value for the rest of the run.
By the time that the pattern is first detected, the opportunity to print that line of input has passed. Any subsequent lines (including additional lines containing the pattern) will print.
add a comment |
awk
for lines after (but not including) the first pattern match
If the line containing the trigger pattern is the equivalent of "CUT HERE", you can omit it from the printed output:
echoer | awk 'flag ; /pattern/ flag=1 '
Each line of input runs through two components in the awk code. The first component is flag
, which awk interprets as "print the line if the variable flag
is nonzero". Since awk variables are 0 by default, this will initially not print anything.
The second component, /pattern/ flag=1
, sets the flag to 1 as soon as it detects the pattern, and the flag keeps that value for the rest of the run.
By the time that the pattern is first detected, the opportunity to print that line of input has passed. Any subsequent lines (including additional lines containing the pattern) will print.
add a comment |
awk
for lines after (but not including) the first pattern match
If the line containing the trigger pattern is the equivalent of "CUT HERE", you can omit it from the printed output:
echoer | awk 'flag ; /pattern/ flag=1 '
Each line of input runs through two components in the awk code. The first component is flag
, which awk interprets as "print the line if the variable flag
is nonzero". Since awk variables are 0 by default, this will initially not print anything.
The second component, /pattern/ flag=1
, sets the flag to 1 as soon as it detects the pattern, and the flag keeps that value for the rest of the run.
By the time that the pattern is first detected, the opportunity to print that line of input has passed. Any subsequent lines (including additional lines containing the pattern) will print.
awk
for lines after (but not including) the first pattern match
If the line containing the trigger pattern is the equivalent of "CUT HERE", you can omit it from the printed output:
echoer | awk 'flag ; /pattern/ flag=1 '
Each line of input runs through two components in the awk code. The first component is flag
, which awk interprets as "print the line if the variable flag
is nonzero". Since awk variables are 0 by default, this will initially not print anything.
The second component, /pattern/ flag=1
, sets the flag to 1 as soon as it detects the pattern, and the flag keeps that value for the rest of the run.
By the time that the pattern is first detected, the opportunity to print that line of input has passed. Any subsequent lines (including additional lines containing the pattern) will print.
answered Mar 29 at 2:53
GaultheriaGaultheria
34214
34214
add a comment |
add a comment |
Bash
A bit clunky, but it works.
#!/bin/bash
found=false
while IFS= read -r; do
if $found || [[ $REPLY =~ pattern ]]; then
found=true
printf '%sn' "$REPLY"
fi
done
This version relies on cat
, but it's easier to understand.
#!/bin/bash
while IFS= read -r; do
if [[ $REPLY =~ pattern ]]; then
printf '%sn' "$REPLY"
break
fi
done
cat
add a comment |
Bash
A bit clunky, but it works.
#!/bin/bash
found=false
while IFS= read -r; do
if $found || [[ $REPLY =~ pattern ]]; then
found=true
printf '%sn' "$REPLY"
fi
done
This version relies on cat
, but it's easier to understand.
#!/bin/bash
while IFS= read -r; do
if [[ $REPLY =~ pattern ]]; then
printf '%sn' "$REPLY"
break
fi
done
cat
add a comment |
Bash
A bit clunky, but it works.
#!/bin/bash
found=false
while IFS= read -r; do
if $found || [[ $REPLY =~ pattern ]]; then
found=true
printf '%sn' "$REPLY"
fi
done
This version relies on cat
, but it's easier to understand.
#!/bin/bash
while IFS= read -r; do
if [[ $REPLY =~ pattern ]]; then
printf '%sn' "$REPLY"
break
fi
done
cat
Bash
A bit clunky, but it works.
#!/bin/bash
found=false
while IFS= read -r; do
if $found || [[ $REPLY =~ pattern ]]; then
found=true
printf '%sn' "$REPLY"
fi
done
This version relies on cat
, but it's easier to understand.
#!/bin/bash
while IFS= read -r; do
if [[ $REPLY =~ pattern ]]; then
printf '%sn' "$REPLY"
break
fi
done
cat
edited Mar 29 at 2:53
answered Mar 29 at 2:18
wjandreawjandrea
504413
504413
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
So pattern can be multiple strings?
– Inian
Mar 28 at 9:41
A glob? Do you mean a regular expression? Globs only make sense for file name expansions.
– terdon♦
Mar 28 at 9:47
@Inian I'm not sure I understand the question. Do you mean to ask if I want this to work with disjunctions?
– user23146
Mar 28 at 10:03