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
  • 711
  • 10
  • 23

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
  • 84,225
  • 14
  • 89
  • 153