0

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.

Thanks

Jeff Stice-Hall
  • 349
  • 2
  • 5
Danny
  • 233
  • 2
  • 8

1 Answers1

0

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

Jeff Stice-Hall
  • 349
  • 2
  • 5
  • 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 07 '11 at 15:55