1

Hi have the following command:

lsscsi | grep HITACHI | awk '{print $6}'

I want that the output will be the number of lines of the original output. For example, if the original output is:

/dev/sda
/dev/sdb
/dev/sdc

The final output will be 3.

Omri
  • 1,456
  • 4
  • 26
  • 51

1 Answers1

4

Basically the command wc -l can be used to count the lines in a file or pipe. However, since you want to count the number of lines after a filter has been applied I would recommend to use grep for that:

lsscsi | grep -c 'HITACHI'

-c just prints the number of matching lines.


Another thing. In your example you are using grep .. | awk. That's a useless use of grep. It should be

lsscsi | awk '/HITACHI/{print $6}'
hek2mgl
  • 143,113
  • 25
  • 227
  • 253