awk: print lines after match to end of file
I'm trying to parse a usage message like:
Usage:
docker-compose [-f <arg>...] [options] [COMMAND] [ARGS...]
docker-compose -h|--help
...
Commands:
build Build or rebuild services
bundle Generate a Docker bundle from the Compose file
...
to grab the Command
names only. So I'm looking to skip all lines up to and including the Commands:
line, then print the first word on all following lines, i.e.
build
bundle
...
Currently I'm doing
docker-compose --help | sed -e '1,/Commands:/d' | awk '{ print $1 }'
and while this works, I suspect I could do the whole thing with a single awk
. The closest I've got so far is:
docker-compose --help | awk '/Commands:/,0 { print $1 }'
But that includes the matched Commands:
line. Can it be done?
text-processing awk
add a comment |
I'm trying to parse a usage message like:
Usage:
docker-compose [-f <arg>...] [options] [COMMAND] [ARGS...]
docker-compose -h|--help
...
Commands:
build Build or rebuild services
bundle Generate a Docker bundle from the Compose file
...
to grab the Command
names only. So I'm looking to skip all lines up to and including the Commands:
line, then print the first word on all following lines, i.e.
build
bundle
...
Currently I'm doing
docker-compose --help | sed -e '1,/Commands:/d' | awk '{ print $1 }'
and while this works, I suspect I could do the whole thing with a single awk
. The closest I've got so far is:
docker-compose --help | awk '/Commands:/,0 { print $1 }'
But that includes the matched Commands:
line. Can it be done?
text-processing awk
add a comment |
I'm trying to parse a usage message like:
Usage:
docker-compose [-f <arg>...] [options] [COMMAND] [ARGS...]
docker-compose -h|--help
...
Commands:
build Build or rebuild services
bundle Generate a Docker bundle from the Compose file
...
to grab the Command
names only. So I'm looking to skip all lines up to and including the Commands:
line, then print the first word on all following lines, i.e.
build
bundle
...
Currently I'm doing
docker-compose --help | sed -e '1,/Commands:/d' | awk '{ print $1 }'
and while this works, I suspect I could do the whole thing with a single awk
. The closest I've got so far is:
docker-compose --help | awk '/Commands:/,0 { print $1 }'
But that includes the matched Commands:
line. Can it be done?
text-processing awk
I'm trying to parse a usage message like:
Usage:
docker-compose [-f <arg>...] [options] [COMMAND] [ARGS...]
docker-compose -h|--help
...
Commands:
build Build or rebuild services
bundle Generate a Docker bundle from the Compose file
...
to grab the Command
names only. So I'm looking to skip all lines up to and including the Commands:
line, then print the first word on all following lines, i.e.
build
bundle
...
Currently I'm doing
docker-compose --help | sed -e '1,/Commands:/d' | awk '{ print $1 }'
and while this works, I suspect I could do the whole thing with a single awk
. The closest I've got so far is:
docker-compose --help | awk '/Commands:/,0 { print $1 }'
But that includes the matched Commands:
line. Can it be done?
text-processing awk
text-processing awk
edited Jun 20 '17 at 2:31
Stephen Rauch
3,344101428
3,344101428
asked Jun 20 '17 at 0:23
ivanivan
722719
722719
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
If you mark the presence of your fence, then you can use it to decide to print the next line and after like:
awk 'x==1 {print $1} /Commands:/ {x=1}'
This is great, thanks. It looks like I don't even need the,0
anymore.
– ivan
Jun 20 '17 at 1:26
1
note thatprint $1
only prints the first word. useprint
orprint $0
to print the whole line
– Chris Maes
Aug 29 '18 at 12:15
add a comment |
Note that 1,/Commands:/d
easily translates to awk
like:
awk 'NR==1, $1 == "Commands:" {next}; NF {print $1}'
A difference with sed
is that it will also work if Command:
is on the first line.
And the NF {print $1}
can be translated to sed
:
sed -n '1,/^Commands:/!s/^[[:blank:]]*([^[:blank:]]{1,}).*/1/p'
add a comment |
sed -n '/Commands:/,$p' filename | awk 'NR!=1{print $1}'
New contributor
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%2f372105%2fawk-print-lines-after-match-to-end-of-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you mark the presence of your fence, then you can use it to decide to print the next line and after like:
awk 'x==1 {print $1} /Commands:/ {x=1}'
This is great, thanks. It looks like I don't even need the,0
anymore.
– ivan
Jun 20 '17 at 1:26
1
note thatprint $1
only prints the first word. useprint
orprint $0
to print the whole line
– Chris Maes
Aug 29 '18 at 12:15
add a comment |
If you mark the presence of your fence, then you can use it to decide to print the next line and after like:
awk 'x==1 {print $1} /Commands:/ {x=1}'
This is great, thanks. It looks like I don't even need the,0
anymore.
– ivan
Jun 20 '17 at 1:26
1
note thatprint $1
only prints the first word. useprint
orprint $0
to print the whole line
– Chris Maes
Aug 29 '18 at 12:15
add a comment |
If you mark the presence of your fence, then you can use it to decide to print the next line and after like:
awk 'x==1 {print $1} /Commands:/ {x=1}'
If you mark the presence of your fence, then you can use it to decide to print the next line and after like:
awk 'x==1 {print $1} /Commands:/ {x=1}'
edited Jun 20 '17 at 2:31
answered Jun 20 '17 at 0:43
Stephen RauchStephen Rauch
3,344101428
3,344101428
This is great, thanks. It looks like I don't even need the,0
anymore.
– ivan
Jun 20 '17 at 1:26
1
note thatprint $1
only prints the first word. useprint
orprint $0
to print the whole line
– Chris Maes
Aug 29 '18 at 12:15
add a comment |
This is great, thanks. It looks like I don't even need the,0
anymore.
– ivan
Jun 20 '17 at 1:26
1
note thatprint $1
only prints the first word. useprint
orprint $0
to print the whole line
– Chris Maes
Aug 29 '18 at 12:15
This is great, thanks. It looks like I don't even need the
,0
anymore.– ivan
Jun 20 '17 at 1:26
This is great, thanks. It looks like I don't even need the
,0
anymore.– ivan
Jun 20 '17 at 1:26
1
1
note that
print $1
only prints the first word. use print
or print $0
to print the whole line– Chris Maes
Aug 29 '18 at 12:15
note that
print $1
only prints the first word. use print
or print $0
to print the whole line– Chris Maes
Aug 29 '18 at 12:15
add a comment |
Note that 1,/Commands:/d
easily translates to awk
like:
awk 'NR==1, $1 == "Commands:" {next}; NF {print $1}'
A difference with sed
is that it will also work if Command:
is on the first line.
And the NF {print $1}
can be translated to sed
:
sed -n '1,/^Commands:/!s/^[[:blank:]]*([^[:blank:]]{1,}).*/1/p'
add a comment |
Note that 1,/Commands:/d
easily translates to awk
like:
awk 'NR==1, $1 == "Commands:" {next}; NF {print $1}'
A difference with sed
is that it will also work if Command:
is on the first line.
And the NF {print $1}
can be translated to sed
:
sed -n '1,/^Commands:/!s/^[[:blank:]]*([^[:blank:]]{1,}).*/1/p'
add a comment |
Note that 1,/Commands:/d
easily translates to awk
like:
awk 'NR==1, $1 == "Commands:" {next}; NF {print $1}'
A difference with sed
is that it will also work if Command:
is on the first line.
And the NF {print $1}
can be translated to sed
:
sed -n '1,/^Commands:/!s/^[[:blank:]]*([^[:blank:]]{1,}).*/1/p'
Note that 1,/Commands:/d
easily translates to awk
like:
awk 'NR==1, $1 == "Commands:" {next}; NF {print $1}'
A difference with sed
is that it will also work if Command:
is on the first line.
And the NF {print $1}
can be translated to sed
:
sed -n '1,/^Commands:/!s/^[[:blank:]]*([^[:blank:]]{1,}).*/1/p'
answered Jun 20 '17 at 5:39
Stéphane ChazelasStéphane Chazelas
309k57582942
309k57582942
add a comment |
add a comment |
sed -n '/Commands:/,$p' filename | awk 'NR!=1{print $1}'
New contributor
add a comment |
sed -n '/Commands:/,$p' filename | awk 'NR!=1{print $1}'
New contributor
add a comment |
sed -n '/Commands:/,$p' filename | awk 'NR!=1{print $1}'
New contributor
sed -n '/Commands:/,$p' filename | awk 'NR!=1{print $1}'
New contributor
edited 8 mins ago
Michael Mrozek♦
61.7k29192211
61.7k29192211
New contributor
answered 1 hour ago
Deepika Reddy BilluriDeepika Reddy Billuri
12
12
New contributor
New contributor
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%2f372105%2fawk-print-lines-after-match-to-end-of-file%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