-1

Let's say the input is something like this:

/dev/sda1 something something word word /dev/sda4/ something word word

I want to achieve this output using grep:

/dev/sda1 /dev/sda4

I currently have this: grep -o "\/dev\/", but it only prints /dev/, and not the rest of the word.

sajmon
  • 131
  • 6
  • Possible duplicate of [How to grep for the whole word](https://stackoverflow.com/q/2879085/608639), [Extract only whole word using grep](https://stackoverflow.com/q/17616012/608639), [How to search for whole words with grep?](https://stackoverflow.com/q/32066451/608639), [Why doesn't grep match a forward-slash at word boundaries](https://stackoverflow.com/q/47743394/608639), [grep string including forward slash as part of word](https://stackoverflow.com/q/49369046/608639), [Sed out word after specific word and /](https://stackoverflow.com/q/35282018/608639), etc. – jww May 06 '18 at 18:27

1 Answers1

1

You can match characters that aren't in a given set of characters like this:

grep -o "/dev/[^ ]*"

(Edited to remove the unnecessary backslashes.)

snowcat
  • 284
  • 1
  • 5