Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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:

00:0f.0 VGA compatible controller: VMware Inc Abstract SVGA II Adapter

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


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.