Take the 2-minute tour ×

I am trying to get the BusID's of each video card stored in a server and putting them in a variable each to be used for an input to a simple find and replace perl script. How would I go about getting the BusID's of each device listed when I run "lspci | grep VGA" for example.


share|improve this question

1 Answer 1

You can use awk to delineate output by spaces. In the fragment below, (assuming a single line was returned by the lspci | grep VGA) the $1 refers to the first component up to a space. $2 would be VGA, $3 compatible, etc ... like this:


In Bash, you would extract the component via awk and assign it to $var, like so:

var=$(lspci |grep VGA | awk '{ print $1 }')

echo $var should return 00:0f.0

share|improve this answer
After re-reading your question, I may have answered the 'wrong' question. Does this help you or were you trying to parse the output of lspci | grep VGA from within perl? –  Jeff Stice-Hall Mar 25 '11 at 22:19
This works for getting that part, unfortunately I needed only the first two digits as they are the BusID. This is how I ended up doing it. @lspciout = lspci | grep VGA foreach my $line (@lspciout){ $_=$line; ($first)=/^(\w\w).+$/; } –  Danny Apr 7 '11 at 15:55

Your Answer


