regex - Regular expression for grep to detect sdaa but not sda -


i want grep devices in linux system except /dev/sda.

my devices f.e.

/dev/sda   /dev/sda2  /dev/sdb    /dev/sdc  /dev/sde  /dev/sdg  /dev/sdi  /dev/sdk /dev/sda1  /dev/sdaa  /dev/sdbb   /dev/sdd  /dev/sdf  /dev/sdh  /dev/sdj  /dev/sdl 

at moment i'm using following command:

ls /dev/sd* | grep '\/dev\/sd[b-z]' 

which not detect /dev/sdaa.

i thought use regular expression this: http://regexr.com/39u99 , invert result of grep -v couldn't work either.

i appreciate :)

edit:

ok many of :) great answers far. extend question case when want exclude /dev/sda1 , /dev/sda2 etc.

meaning /dev/sda , /dev/sda1 /dev/sda2 /dev/sda3 etc.

you there, below regex you.

\/dev\/sd(a{2}|[b-z]+) 


$ grep -po '\/dev\/sd(a{2}|[b-z]+)' file.txt  /dev/sdb /dev/sdc /dev/sde /dev/sdg /dev/sdi /dev/sdk /dev/sdaa /dev/sdbb /dev/sdd /dev/sdf /dev/sdh /dev/sdj /dev/sdl 

and here regex demo

instead of regex can try bash negation feature this.

$ ls  !(sda[0-9]) sdaa  sdb  sdbb  sdc  sdd  sde  sdf  sdg  sdh  sdi  sdj  sdk  sdl 

the negation more effective simple filtering.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

How do you convert a timestamp into a datetime in python with the correct timezone? -