Merge two greps into single one The 2019 Stack Overflow Developer Survey Results Are In Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar Manara 2019 Community Moderator Election ResultsNeed to parse a double entry table with two pairsMerge two lists while removing duplicatesRetrieving two matches from repeated patternGroup matching with grep includes extra charactersGrep on single lineGrep / awk on multiple files to single outputCombine two greps into a single commandone-liner command to rename a file using the output of another commandGrep multiple files and output to multiple files in a single commandGrep 3 Capital Letters and Digits into Two Variables
Why are PDP-7-style microprogrammed instructions out of vogue?
Did the UK government pay "millions and millions of dollars" to try to snag Julian Assange?
What information about me do stores get via my credit card?
Working through the single responsibility principle (SRP) in Python when calls are expensive
Why can't devices on different VLANs, but on the same subnet, communicate?
"... to apply for a visa" or "... and applied for a visa"?
Why doesn't a hydraulic lever violate conservation of energy?
Is every episode of "Where are my Pants?" identical?
Deal with toxic manager when you can't quit
Can each chord in a progression create its own key?
Are spiders unable to hurt humans, especially very small spiders?
What's the point in a preamp?
Is there a writing software that you can sort scenes like slides in PowerPoint?
How did the crowd guess the pentatonic scale in Bobby McFerrin's presentation?
Was credit for the black hole image misappropriated?
What can I do to 'burn' a journal?
What happens to a Warlock's expended Spell Slots when they gain a Level?
One-dimensional Japanese puzzle
For what reasons would an animal species NOT cross a *horizontal* land bridge?
Is 'stolen' appropriate word?
My body leaves; my core can stay
Is this wall load bearing? Blueprints and photos attached
Store Dynamic-accessible hidden metadata in a cell
Can I visit the Trinity College (Cambridge) library and see some of their rare books
Merge two greps into single one
The 2019 Stack Overflow Developer Survey Results Are In
Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar Manara
2019 Community Moderator Election ResultsNeed to parse a double entry table with two pairsMerge two lists while removing duplicatesRetrieving two matches from repeated patternGroup matching with grep includes extra charactersGrep on single lineGrep / awk on multiple files to single outputCombine two greps into a single commandone-liner command to rename a file using the output of another commandGrep multiple files and output to multiple files in a single commandGrep 3 Capital Letters and Digits into Two Variables
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I need to extract an ID from the output of another command. Currently my extracting command looks like:
someID=$(command | grep -oP '(?:^Successfullysbuilts)([da-z]12$)' | grep -oP '([a-zd]12)')
Example command output:
---> Using cache
---> 9b4624927fa6
Successfully built 9b4624927fa6
Expected result:
9b4624927fa6
ID extracted from line
Successfully built 9b4624927fa6
How could I merge those two grep statements into single one?
grep regular-expression
New contributor
stetoc is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
I need to extract an ID from the output of another command. Currently my extracting command looks like:
someID=$(command | grep -oP '(?:^Successfullysbuilts)([da-z]12$)' | grep -oP '([a-zd]12)')
Example command output:
---> Using cache
---> 9b4624927fa6
Successfully built 9b4624927fa6
Expected result:
9b4624927fa6
ID extracted from line
Successfully built 9b4624927fa6
How could I merge those two grep statements into single one?
grep regular-expression
New contributor
stetoc is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I don't really understand your question. Your command seems to do exactly what you want.
– Sjoerd
yesterday
6
If you are building a docker image, you can give it a name with the--tagoption. That way, you can supply the name instead of having to parse it from the output. Also,--quietsupresses all output except for the image ID.
– Sjoerd
yesterday
@Sjoerd Yes, but they want to combine the twogrepcalls into a single command.
– Kusalananda♦
yesterday
@Sjoerd oh thanks for suggestion, will definitely try it, I need that id exactly for this reason, want to build simple automated pipeline for docker containers
– stetoc
yesterday
add a comment |
I need to extract an ID from the output of another command. Currently my extracting command looks like:
someID=$(command | grep -oP '(?:^Successfullysbuilts)([da-z]12$)' | grep -oP '([a-zd]12)')
Example command output:
---> Using cache
---> 9b4624927fa6
Successfully built 9b4624927fa6
Expected result:
9b4624927fa6
ID extracted from line
Successfully built 9b4624927fa6
How could I merge those two grep statements into single one?
grep regular-expression
New contributor
stetoc is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I need to extract an ID from the output of another command. Currently my extracting command looks like:
someID=$(command | grep -oP '(?:^Successfullysbuilts)([da-z]12$)' | grep -oP '([a-zd]12)')
Example command output:
---> Using cache
---> 9b4624927fa6
Successfully built 9b4624927fa6
Expected result:
9b4624927fa6
ID extracted from line
Successfully built 9b4624927fa6
How could I merge those two grep statements into single one?
grep regular-expression
grep regular-expression
New contributor
stetoc is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
stetoc is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 22 hours ago
John Kugelman
1,45111020
1,45111020
New contributor
stetoc is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked yesterday
stetocstetoc
1184
1184
New contributor
stetoc is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
stetoc is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
stetoc is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I don't really understand your question. Your command seems to do exactly what you want.
– Sjoerd
yesterday
6
If you are building a docker image, you can give it a name with the--tagoption. That way, you can supply the name instead of having to parse it from the output. Also,--quietsupresses all output except for the image ID.
– Sjoerd
yesterday
@Sjoerd Yes, but they want to combine the twogrepcalls into a single command.
– Kusalananda♦
yesterday
@Sjoerd oh thanks for suggestion, will definitely try it, I need that id exactly for this reason, want to build simple automated pipeline for docker containers
– stetoc
yesterday
add a comment |
I don't really understand your question. Your command seems to do exactly what you want.
– Sjoerd
yesterday
6
If you are building a docker image, you can give it a name with the--tagoption. That way, you can supply the name instead of having to parse it from the output. Also,--quietsupresses all output except for the image ID.
– Sjoerd
yesterday
@Sjoerd Yes, but they want to combine the twogrepcalls into a single command.
– Kusalananda♦
yesterday
@Sjoerd oh thanks for suggestion, will definitely try it, I need that id exactly for this reason, want to build simple automated pipeline for docker containers
– stetoc
yesterday
I don't really understand your question. Your command seems to do exactly what you want.
– Sjoerd
yesterday
I don't really understand your question. Your command seems to do exactly what you want.
– Sjoerd
yesterday
6
6
If you are building a docker image, you can give it a name with the
--tag option. That way, you can supply the name instead of having to parse it from the output. Also, --quiet supresses all output except for the image ID.– Sjoerd
yesterday
If you are building a docker image, you can give it a name with the
--tag option. That way, you can supply the name instead of having to parse it from the output. Also, --quiet supresses all output except for the image ID.– Sjoerd
yesterday
@Sjoerd Yes, but they want to combine the two
grep calls into a single command.– Kusalananda♦
yesterday
@Sjoerd Yes, but they want to combine the two
grep calls into a single command.– Kusalananda♦
yesterday
@Sjoerd oh thanks for suggestion, will definitely try it, I need that id exactly for this reason, want to build simple automated pipeline for docker containers
– stetoc
yesterday
@Sjoerd oh thanks for suggestion, will definitely try it, I need that id exactly for this reason, want to build simple automated pipeline for docker containers
– stetoc
yesterday
add a comment |
2 Answers
2
active
oldest
votes
A slight modification of your first grep works for me:
$ grep -oP '^SuccessfullysbuiltsK[da-z]12$' example-output
9b4624927fa6
K in PCRE resets the match start:
The escape sequence
Kcauses any previously matched characters not to
be included in the final matched sequence.
It's similar to a zero-width positive look-behind assertion (?<=Successfully...).
4
Kis not a look behind assertion, it just sets the start of the matched text here reported by-o. Compareecho aaaaa | grep -Po 'aK.'withecho aaaaa | grep -Po '(?<=a).'(this time using a look-behind assertion).
– Stéphane Chazelas
yesterday
1
@StéphaneChazelas: To be fair,perlredescribes it in the same list item as positive look-behind assertions, with language and typography that strongly suggests thinking of one as a variant of the other (even though that can't be the case at a technical level).
– Henning Makholm
yesterday
1
@HenningMakholm, yes, it's unfortunate. Thepcrepatternman page does not make that confusion. It's trueKcan often be used in place or positive look behind assertions.
– Stéphane Chazelas
yesterday
@StéphaneChazelas thanks, corrected.
– muru
17 hours ago
add a comment |
To get the hexadecimal number at the end of a line that starts with Successfully built, I would probably use sed:
sed -n -E 's/^Successfully built ([[:xdigit:]]+)$/1/p'
This replaces the matching line with the hash and prints it (and no other line).
Or awk:
awk '/^Successfully built [[:xdigit:]]+$/ print $NF '
This prints the last whitespace-delimited field of each line matching the regular expression.
In both regular expressions, the [[:xdigit:]]+ expression will match a non-empty string of hexadecimal digits.
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
);
);
stetoc is a new contributor. Be nice, and check out our Code of Conduct.
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%2f511837%2fmerge-two-greps-into-single-one%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
A slight modification of your first grep works for me:
$ grep -oP '^SuccessfullysbuiltsK[da-z]12$' example-output
9b4624927fa6
K in PCRE resets the match start:
The escape sequence
Kcauses any previously matched characters not to
be included in the final matched sequence.
It's similar to a zero-width positive look-behind assertion (?<=Successfully...).
4
Kis not a look behind assertion, it just sets the start of the matched text here reported by-o. Compareecho aaaaa | grep -Po 'aK.'withecho aaaaa | grep -Po '(?<=a).'(this time using a look-behind assertion).
– Stéphane Chazelas
yesterday
1
@StéphaneChazelas: To be fair,perlredescribes it in the same list item as positive look-behind assertions, with language and typography that strongly suggests thinking of one as a variant of the other (even though that can't be the case at a technical level).
– Henning Makholm
yesterday
1
@HenningMakholm, yes, it's unfortunate. Thepcrepatternman page does not make that confusion. It's trueKcan often be used in place or positive look behind assertions.
– Stéphane Chazelas
yesterday
@StéphaneChazelas thanks, corrected.
– muru
17 hours ago
add a comment |
A slight modification of your first grep works for me:
$ grep -oP '^SuccessfullysbuiltsK[da-z]12$' example-output
9b4624927fa6
K in PCRE resets the match start:
The escape sequence
Kcauses any previously matched characters not to
be included in the final matched sequence.
It's similar to a zero-width positive look-behind assertion (?<=Successfully...).
4
Kis not a look behind assertion, it just sets the start of the matched text here reported by-o. Compareecho aaaaa | grep -Po 'aK.'withecho aaaaa | grep -Po '(?<=a).'(this time using a look-behind assertion).
– Stéphane Chazelas
yesterday
1
@StéphaneChazelas: To be fair,perlredescribes it in the same list item as positive look-behind assertions, with language and typography that strongly suggests thinking of one as a variant of the other (even though that can't be the case at a technical level).
– Henning Makholm
yesterday
1
@HenningMakholm, yes, it's unfortunate. Thepcrepatternman page does not make that confusion. It's trueKcan often be used in place or positive look behind assertions.
– Stéphane Chazelas
yesterday
@StéphaneChazelas thanks, corrected.
– muru
17 hours ago
add a comment |
A slight modification of your first grep works for me:
$ grep -oP '^SuccessfullysbuiltsK[da-z]12$' example-output
9b4624927fa6
K in PCRE resets the match start:
The escape sequence
Kcauses any previously matched characters not to
be included in the final matched sequence.
It's similar to a zero-width positive look-behind assertion (?<=Successfully...).
A slight modification of your first grep works for me:
$ grep -oP '^SuccessfullysbuiltsK[da-z]12$' example-output
9b4624927fa6
K in PCRE resets the match start:
The escape sequence
Kcauses any previously matched characters not to
be included in the final matched sequence.
It's similar to a zero-width positive look-behind assertion (?<=Successfully...).
edited 17 hours ago
answered yesterday
murumuru
37.6k589165
37.6k589165
4
Kis not a look behind assertion, it just sets the start of the matched text here reported by-o. Compareecho aaaaa | grep -Po 'aK.'withecho aaaaa | grep -Po '(?<=a).'(this time using a look-behind assertion).
– Stéphane Chazelas
yesterday
1
@StéphaneChazelas: To be fair,perlredescribes it in the same list item as positive look-behind assertions, with language and typography that strongly suggests thinking of one as a variant of the other (even though that can't be the case at a technical level).
– Henning Makholm
yesterday
1
@HenningMakholm, yes, it's unfortunate. Thepcrepatternman page does not make that confusion. It's trueKcan often be used in place or positive look behind assertions.
– Stéphane Chazelas
yesterday
@StéphaneChazelas thanks, corrected.
– muru
17 hours ago
add a comment |
4
Kis not a look behind assertion, it just sets the start of the matched text here reported by-o. Compareecho aaaaa | grep -Po 'aK.'withecho aaaaa | grep -Po '(?<=a).'(this time using a look-behind assertion).
– Stéphane Chazelas
yesterday
1
@StéphaneChazelas: To be fair,perlredescribes it in the same list item as positive look-behind assertions, with language and typography that strongly suggests thinking of one as a variant of the other (even though that can't be the case at a technical level).
– Henning Makholm
yesterday
1
@HenningMakholm, yes, it's unfortunate. Thepcrepatternman page does not make that confusion. It's trueKcan often be used in place or positive look behind assertions.
– Stéphane Chazelas
yesterday
@StéphaneChazelas thanks, corrected.
– muru
17 hours ago
4
4
K is not a look behind assertion, it just sets the start of the matched text here reported by -o. Compare echo aaaaa | grep -Po 'aK.' with echo aaaaa | grep -Po '(?<=a).' (this time using a look-behind assertion).– Stéphane Chazelas
yesterday
K is not a look behind assertion, it just sets the start of the matched text here reported by -o. Compare echo aaaaa | grep -Po 'aK.' with echo aaaaa | grep -Po '(?<=a).' (this time using a look-behind assertion).– Stéphane Chazelas
yesterday
1
1
@StéphaneChazelas: To be fair,
perlre describes it in the same list item as positive look-behind assertions, with language and typography that strongly suggests thinking of one as a variant of the other (even though that can't be the case at a technical level).– Henning Makholm
yesterday
@StéphaneChazelas: To be fair,
perlre describes it in the same list item as positive look-behind assertions, with language and typography that strongly suggests thinking of one as a variant of the other (even though that can't be the case at a technical level).– Henning Makholm
yesterday
1
1
@HenningMakholm, yes, it's unfortunate. The
pcrepattern man page does not make that confusion. It's true K can often be used in place or positive look behind assertions.– Stéphane Chazelas
yesterday
@HenningMakholm, yes, it's unfortunate. The
pcrepattern man page does not make that confusion. It's true K can often be used in place or positive look behind assertions.– Stéphane Chazelas
yesterday
@StéphaneChazelas thanks, corrected.
– muru
17 hours ago
@StéphaneChazelas thanks, corrected.
– muru
17 hours ago
add a comment |
To get the hexadecimal number at the end of a line that starts with Successfully built, I would probably use sed:
sed -n -E 's/^Successfully built ([[:xdigit:]]+)$/1/p'
This replaces the matching line with the hash and prints it (and no other line).
Or awk:
awk '/^Successfully built [[:xdigit:]]+$/ print $NF '
This prints the last whitespace-delimited field of each line matching the regular expression.
In both regular expressions, the [[:xdigit:]]+ expression will match a non-empty string of hexadecimal digits.
add a comment |
To get the hexadecimal number at the end of a line that starts with Successfully built, I would probably use sed:
sed -n -E 's/^Successfully built ([[:xdigit:]]+)$/1/p'
This replaces the matching line with the hash and prints it (and no other line).
Or awk:
awk '/^Successfully built [[:xdigit:]]+$/ print $NF '
This prints the last whitespace-delimited field of each line matching the regular expression.
In both regular expressions, the [[:xdigit:]]+ expression will match a non-empty string of hexadecimal digits.
add a comment |
To get the hexadecimal number at the end of a line that starts with Successfully built, I would probably use sed:
sed -n -E 's/^Successfully built ([[:xdigit:]]+)$/1/p'
This replaces the matching line with the hash and prints it (and no other line).
Or awk:
awk '/^Successfully built [[:xdigit:]]+$/ print $NF '
This prints the last whitespace-delimited field of each line matching the regular expression.
In both regular expressions, the [[:xdigit:]]+ expression will match a non-empty string of hexadecimal digits.
To get the hexadecimal number at the end of a line that starts with Successfully built, I would probably use sed:
sed -n -E 's/^Successfully built ([[:xdigit:]]+)$/1/p'
This replaces the matching line with the hash and prints it (and no other line).
Or awk:
awk '/^Successfully built [[:xdigit:]]+$/ print $NF '
This prints the last whitespace-delimited field of each line matching the regular expression.
In both regular expressions, the [[:xdigit:]]+ expression will match a non-empty string of hexadecimal digits.
answered yesterday
Kusalananda♦Kusalananda
141k17263439
141k17263439
add a comment |
add a comment |
stetoc is a new contributor. Be nice, and check out our Code of Conduct.
stetoc is a new contributor. Be nice, and check out our Code of Conduct.
stetoc is a new contributor. Be nice, and check out our Code of Conduct.
stetoc 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.
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%2f511837%2fmerge-two-greps-into-single-one%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
-grep, regular-expression
I don't really understand your question. Your command seems to do exactly what you want.
– Sjoerd
yesterday
6
If you are building a docker image, you can give it a name with the
--tagoption. That way, you can supply the name instead of having to parse it from the output. Also,--quietsupresses all output except for the image ID.– Sjoerd
yesterday
@Sjoerd Yes, but they want to combine the two
grepcalls into a single command.– Kusalananda♦
yesterday
@Sjoerd oh thanks for suggestion, will definitely try it, I need that id exactly for this reason, want to build simple automated pipeline for docker containers
– stetoc
yesterday