Search code examples
linuxcentosextract

display drives with lsblk -o name -lpn , extract string containing "sd"


So I've looked all over the place for what to do here and just find "from file". I am looking to extract from a command output.

Task: display the absolute path names of disks beginning with the sd.

Current progress: displaying absolute path name of disks

[host /]$ lsblk -o name -lpn
/dev/sda
/dev/sda1
/dev/mapper/centos-root
/dev/sda2
/dev/md127
....

Desired output

/dev/sda
/dev/sda1
/dev/sda2
....

I've played around with cut, print, awk and sed.

Got syntax errors or no output.


Solution

  • grep

    lsblk -o name -lpn | grep "/dev/sd"
    

    awk

    lsblk -o name -lpn | awk '/dev\/sd/{print}'
    

    sed

    lsblk -o name -lpn | sed -n '/\/dev\/sd/p'
    

    Output:

    /dev/sda
    /dev/sda1
    /dev/sda2