Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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
share|improve this question

migrated from serverfault.com Dec 5 '13 at 0:53

This question came from our site for system and network administrators.

    
For what purpose? See man awk, or man cut for a starting point. –  Zoredache Dec 4 '13 at 17:49

1 Answer 1

up vote 5 down vote accepted

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' '
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.