2

I would like to parse the column elements of the output from the command lsscsi.

Here is a sample output,

# lsscsi

[0:0:0:0]   disk   ATA   VBOX HARDDISK   1.0   /dev/sda
[0:0:1:0]   disk   ATA   VBOX HARDDISK   1.0   /dev/sdb
[1:0:1:0]   disk   ATA   VBOX HARDDISK   1.0   /dev/sdc

Example if I want column 2, my output should be,

disk
disk
disk

If column 7,

/dev/sda
/dev/sdb
/dev/sdc
1
  • For what purpose? See man awk, or man cut for a starting point. Commented Dec 4, 2013 at 17:49

1 Answer 1

6

the awk utility could be your friend

lsscsi | awk '{print $7}'
/dev/sda
/dev/sdb
/dev/sdc

lsscsi | awk '{print $2}'
disk
disk
disk

or you could use cut but you may need to mess about with the spaces first

lsscsi | sed 's/ \+/ /g' | cut -f7 -d' '

You must log in to answer this question.