1

I am trying to grab the sda# of a drive that was just inserted.

tail -f /var/log/messages | grep sda:

Returns: Mar 12 17:21:55 raspberrypi kernel: [ 1133.736632] sda: sda1

I would like to grab the sda1 part of the stdout, how would I do that?

Nicholas Adamou
  • 591
  • 3
  • 17

1 Answers1

2

I suggest to use this with GNU grep:

| grep -Po 'sd[a-z]+: \Ksd[a-z0-9]+$'

\K: This sequence resets the starting point of the reported match. Any previously matched characters are not included in the final matched sequence.


See: The Stack Overflow Regular Expressions FAQ

Community
  • 1
  • 1
Cyrus
  • 69,405
  • 13
  • 65
  • 117
  • [Please vote if the answer was helpful.](http://stackoverflow.com/help/someone-answers) – Cyrus Mar 12 '17 at 17:46