1

I have this output in my shell by typing the command foobar:

NAME                                               ZONE            STATUS   ACTION  LAST_ERROR
foobar--docker-worker-yyb55u-4ivg  europe-west1-c  RUNNING  NONE

I want to grep the complete name. Which I try doing like this:

$ foobar | grep -q -P "(foobar--[^\s]+)" but this returns me: foobar--docker-worker-yyb55u-4ivg europe-west1-c RUNNING NONE

Which I don't understand because I tested the regex here: https://regex101.com/r/sX471v/1

Any advice is welcome, thanks!

Bob van Luijt
  • 7,153
  • 12
  • 58
  • 101

1 Answers1

1

grep display the full line where a match occurs by default. Use its -o option to prevent this behaviour and display the match only. You also need to remove the -q "quiet" option which removes all output :

foobar | grep -Po "(foobar--[^\s]+)"
Aaron
  • 24,009
  • 2
  • 33
  • 57