Awk: print lines after match to end of file

awktext processing

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?

Best Answer

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}'
Related Question