Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #176299 > unrolled thread

[OT] get all devices from a vendor from pci.ids

Started byFloris <jkfloris@dds.nl>
First post2017-01-04 17:40 +0100
Last post2017-01-05 21:10 +0100
Articles 9 — 3 participants

Back to article view | Back to linux.debian.user


Contents

  [OT] get all devices from a vendor from pci.ids Floris <jkfloris@dds.nl> - 2017-01-04 17:40 +0100
    Re: [OT] get all devices from a vendor from pci.ids Floris <jkfloris@dds.nl> - 2017-01-05 18:10 +0100
      Re: [OT] get all devices from a vendor from pci.ids Javier Barroso <javibarroso@gmail.com> - 2017-01-05 18:20 +0100
        Re: [OT] get all devices from a vendor from pci.ids Nicolas George <george@nsup.org> - 2017-01-05 21:10 +0100
          Re: [OT] get all devices from a vendor from pci.ids Floris <jkfloris@dds.nl> - 2017-01-05 21:20 +0100
            Re: [OT] get all devices from a vendor from pci.ids Javier Barroso <javibarroso@gmail.com> - 2017-01-06 22:40 +0100
              When do I use perl, awk, sed, grep, cut etc.. Was[OT] get all devices  from a vendor from pci.ids Floris <jkfloris@dds.nl> - 2017-01-06 22:50 +0100
                Re: When do I use perl, awk, sed, grep, cut etc.. Was[OT] get all  devices from a vendor from pci.ids Javier Barroso <javibarroso@gmail.com> - 2017-01-06 23:50 +0100
        Re: [OT] get all devices from a vendor from pci.ids Floris <jkfloris@dds.nl> - 2017-01-05 21:10 +0100

#176299 — [OT] get all devices from a vendor from pci.ids

FromFloris <jkfloris@dds.nl>
Date2017-01-04 17:40 +0100
Subject[OT] get all devices from a vendor from pci.ids
Message-ID<sVWLw-79z-49@gated-at.bofh.it>
(Not really a Debian question, but I know there are smart people on this  
list.)

I want to search the pci.ids file (from the pciutils package) for all  
Compaq devices.
Pci ID's 0e11:xxxx , 1032:xxxx and 10da:xxxx matches Compaq.  
Unfortunately, only at a beginning of a list the id of the vendor is  
printed in column 1. The id of the devices are printed in column 2, with  
an empty first column.

(part of pci.ids)
...
0e11  Compaq Computer Corporation
	0001  PCI to EISA Bridge
	0002  PCI to ISA Bridge
	0046  Smart Array 64xx
		0e11 4091  Smart Array 6i
		0e11 409a  Smart Array 641
		0e11 409b  Smart Array 642
		0e11 409c  Smart Array 6400
		0e11 409d  Smart Array 6400 EM
	0049  NC7132 Gigabit Upgrade Module
	004a  NC6136 Gigabit Server Adapter
...
	c000  Remote Insight Lights-Out Edition
	f130  NetFlex-3/P ThunderLAN 1.0
	f150  NetFlex-3/P ThunderLAN 2.3
0e55  HaSoTec GmbH
...

Is there an awk, grep and or sed solution?

Floris

[toc] | [next] | [standalone]


#176335

FromFloris <jkfloris@dds.nl>
Date2017-01-05 18:10 +0100
Message-ID<sWjI5-5Ut-23@gated-at.bofh.it>
In reply to#176299
Op Wed, 04 Jan 2017 17:27:55 +0100 schreef Floris <jkfloris@dds.nl>:

> (Not really a Debian question, but I know there are smart people on this  
> list.)
>
> I want to search the pci.ids file (from the pciutils package) for all  
> Compaq devices.
> Pci ID's 0e11:xxxx , 1032:xxxx and 10da:xxxx matches Compaq.  
> Unfortunately, only at a beginning of a list the id of the vendor is  
> printed in column 1. The id of the devices are printed in column 2, with  
> an empty first column.
>
> (part of pci.ids)
> ...
> 0e11  Compaq Computer Corporation
> 	0001  PCI to EISA Bridge
> 	0002  PCI to ISA Bridge
> 	0046  Smart Array 64xx
> 		0e11 4091  Smart Array 6i
> 		0e11 409a  Smart Array 641
> 		0e11 409b  Smart Array 642
> 		0e11 409c  Smart Array 6400
> 		0e11 409d  Smart Array 6400 EM
> 	0049  NC7132 Gigabit Upgrade Module
> 	004a  NC6136 Gigabit Server Adapter
> ...
> 	c000  Remote Insight Lights-Out Edition
> 	f130  NetFlex-3/P ThunderLAN 1.0
> 	f150  NetFlex-3/P ThunderLAN 2.3
> 0e55  HaSoTec GmbH
> ...
>
> Is there an awk, grep and or sed solution?
>
> Floris
>

an other solution would be something like:

# cat pci.ids | {magic-command} 0e11:004a
NC6136 Gigabit Server Adapter

what is the magic command?

Floris

[toc] | [prev] | [next] | [standalone]


#176336

FromJavier Barroso <javibarroso@gmail.com>
Date2017-01-05 18:20 +0100
Message-ID<sWjRL-5ZY-11@gated-at.bofh.it>
In reply to#176335
Hello,


On Thu, Jan 5, 2017 at 6:00 PM, Floris <jkfloris@dds.nl> wrote:
> Op Wed, 04 Jan 2017 17:27:55 +0100 schreef Floris <jkfloris@dds.nl>:
>
>
>> (Not really a Debian question, but I know there are smart people on this
>> list.)
>>
>> I want to search the pci.ids file (from the pciutils package) for all
>> Compaq devices.
>> Pci ID's 0e11:xxxx , 1032:xxxx and 10da:xxxx matches Compaq.
>> Unfortunately, only at a beginning of a list the id of the vendor is printed
>> in column 1. The id of the devices are printed in column 2, with an empty
>> first column.
>>
>> (part of pci.ids)
>> ...
>> 0e11  Compaq Computer Corporation
>>         0001  PCI to EISA Bridge
>>         0002  PCI to ISA Bridge
>>         0046  Smart Array 64xx
>>                 0e11 4091  Smart Array 6i
>>                 0e11 409a  Smart Array 641
>>                 0e11 409b  Smart Array 642
>>                 0e11 409c  Smart Array 6400
>>                 0e11 409d  Smart Array 6400 EM
>>         0049  NC7132 Gigabit Upgrade Module
>>         004a  NC6136 Gigabit Server Adapter
>> ...
>>         c000  Remote Insight Lights-Out Edition
>>         f130  NetFlex-3/P ThunderLAN 1.0
>>         f150  NetFlex-3/P ThunderLAN 2.3
>> 0e55  HaSoTec GmbH
>> ...
>>
>> Is there an awk, grep and or sed solution?
>>
>> Floris
>>
>
> an other solution would be something like:
>
> # cat pci.ids | {magic-command} 0e11:004a
> NC6136 Gigabit Server Adapter
>
> what is the magic command?

Using perl:

perl -ne 'print if (/^0e11/.../^\S/) and (/^\s/) or (/^0e11/);'
/usr/share/misc/pci.ids

[toc] | [prev] | [next] | [standalone]


#176339

FromNicolas George <george@nsup.org>
Date2017-01-05 21:10 +0100
Message-ID<sWmwi-7Lg-29@gated-at.bofh.it>
In reply to#176336

[Multipart message — attachments visible in raw view] — view raw

Le sextidi 16 nivôse, an CCXXV, Floris a écrit :
> Thanks! But I prefer a solution with "essential" Debian software/ packages

~ $ dpkg -S =perl
perl-base: /usr/bin/perl
~ $ dpkg -s perl-base | head -n 2
Package: perl-base
Essential: yes

[toc] | [prev] | [next] | [standalone]


#176341

FromFloris <jkfloris@dds.nl>
Date2017-01-05 21:20 +0100
Message-ID<sWmFY-7Qg-41@gated-at.bofh.it>
In reply to#176339
Op Thu, 05 Jan 2017 21:07:10 +0100 schreef Nicolas George  
<george@nsup.org>:

> Le sextidi 16 nivôse, an CCXXV, Floris a écrit :
>> Thanks! But I prefer a solution with "essential" Debian software/  
>> packages
>
> ~ $ dpkg -S =perl
> perl-base: /usr/bin/perl
> ~ $ dpkg -s perl-base | head -n 2
> Package: perl-base
> Essential: yes

Sorry, I only looked at the perl package
dpkg -s perl
Package: perl
Status: install ok installed
Priority: standard
Section: perl

So every Debian user has the perl command?

Floris

[toc] | [prev] | [next] | [standalone]


#176391

FromJavier Barroso <javibarroso@gmail.com>
Date2017-01-06 22:40 +0100
Message-ID<sWKoW-7NO-35@gated-at.bofh.it>
In reply to#176341
Hello,

On Thu, Jan 5, 2017 at 9:13 PM, Floris <jkfloris@dds.nl> wrote:
> Op Thu, 05 Jan 2017 21:07:10 +0100 schreef Nicolas George <george@nsup.org>:
>
>
>> Le sextidi 16 nivôse, an CCXXV, Floris a écrit :
>>>
>>> Thanks! But I prefer a solution with "essential" Debian software/
>>> packages
>>
>>
>> ~ $ dpkg -S =perl
>> perl-base: /usr/bin/perl
>> ~ $ dpkg -s perl-base | head -n 2
>> Package: perl-base
>> Essential: yes
>
>
> Sorry, I only looked at the perl package
> dpkg -s perl
> Package: perl
> Status: install ok installed
> Priority: standard
> Section: perl
>
> So every Debian user has the perl command?
Not only Debian users, the vast majority of linux / unix users have
perl installed (maybe now that android is here, this statement is not
true any more ...

With awk:
awk -v vendor=0e11 'p == 1 && /^[^[:space:]]/ { p=0; } $0 ~ "^"vendor"
" {p=1;} p' /usr/share/misc/pci.ids

With sed:
sed -ne '/^0e11/p' -e '/^0e11/,/^[^[:space:]]/ { /^[^[:space:]]/d ; p
}'  /usr/share/misc/pci.ids

Wrapping to script which get an argument is easy

Regards

[toc] | [prev] | [next] | [standalone]


#176395 — When do I use perl, awk, sed, grep, cut etc.. Was[OT] get all devices from a vendor from pci.ids

FromFloris <jkfloris@dds.nl>
Date2017-01-06 22:50 +0100
SubjectWhen do I use perl, awk, sed, grep, cut etc.. Was[OT] get all devices from a vendor from pci.ids
Message-ID<sWKyD-7RC-41@gated-at.bofh.it>
In reply to#176391
>> So every Debian user has the perl command?
> Not only Debian users, the vast majority of linux / unix users have
> perl installed (maybe now that android is here, this statement is not
> true any more ...
>
> With awk:
> awk -v vendor=0e11 'p == 1 && /^[^[:space:]]/ { p=0; } $0 ~ "^"vendor"
> " {p=1;} p' /usr/share/misc/pci.ids
>
> With sed:
> sed -ne '/^0e11/p' -e '/^0e11/,/^[^[:space:]]/ { /^[^[:space:]]/d ; p
> }'  /usr/share/misc/pci.ids
>
> Wrapping to script which get an argument is easy
>
> Regards
>

Thanks for your answer, and the next question pops in.

Is there a "rule" when I use perl, awk, sed, grep, cut etc. in a script?
Often I find multiple solutions on the Internet to achieve the same output.

A simple example:

cut -d: -f2
or
awk -F: '{ print $2 }'

Is the one better as the other (CPU/RAM usage), or is it just "taste"

Floris

[toc] | [prev] | [next] | [standalone]


#176398 — Re: When do I use perl, awk, sed, grep, cut etc.. Was[OT] get all devices from a vendor from pci.ids

FromJavier Barroso <javibarroso@gmail.com>
Date2017-01-06 23:50 +0100
SubjectRe: When do I use perl, awk, sed, grep, cut etc.. Was[OT] get all devices from a vendor from pci.ids
Message-ID<sWLuG-4T-39@gated-at.bofh.it>
In reply to#176395
Hello,

On Fri, Jan 6, 2017 at 10:46 PM, Floris <jkfloris@dds.nl> wrote:
>>> So every Debian user has the perl command?
>>
>> Not only Debian users, the vast majority of linux / unix users have
>> perl installed (maybe now that android is here, this statement is not
>> true any more ...
>>
>> With awk:
>> awk -v vendor=0e11 'p == 1 && /^[^[:space:]]/ { p=0; } $0 ~ "^"vendor"
>> " {p=1;} p' /usr/share/misc/pci.ids
>>
>> With sed:
>> sed -ne '/^0e11/p' -e '/^0e11/,/^[^[:space:]]/ { /^[^[:space:]]/d ; p
>> }'  /usr/share/misc/pci.ids
>>
>> Wrapping to script which get an argument is easy
>>
>> Regards
>>
>
> Thanks for your answer, and the next question pops in.
>
> Is there a "rule" when I use perl, awk, sed, grep, cut etc. in a script?
> Often I find multiple solutions on the Internet to achieve the same output.
>
> A simple example:
>
> cut -d: -f2
> or
> awk -F: '{ print $2 }'
>
> Is the one better as the other (CPU/RAM usage), or is it just "taste"

I'm pretty sure that there are tools to help meassure ram / cpu used
by a shell script and then present result (max / min / media ...), but
I don't know any one (maybe memusg from a quick google search). I
would limit memory though ulimit -m to the memory that I would have to
run the script.

If a tool will not be executed thousands of times is irrelevant if it
is using cut / awk or another shell basic command. Why would you spend
more time on an script to optimize it if it won't run many times?
Even, if it will be executed by cron task, It is not important if it
takes one second, or ten seconds. Of course if it is a public script
is important, you don't know how many times it will be executed, the
less time take the script , less time are lost by future users ...

For a simple cpu benchmark, sorted by real and user % cpu:

$ time for i in {1..1000} ; do ./test_awk > /dev/null ; done

real    0m33,671s
user    0m28,384s
sys     0m1,228s
$ time for i in {1..1000} ; do ./test_bash > /dev/null ; done

real    0m29,404s
user    0m26,708s
sys     0m1,344s
$ time for i in {1..1000} ; do ./test_sed > /dev/null ; done

real    0m16,765s
user    0m12,452s
sys     0m0,820s
$ time for i in {1..1000} ; do ./test_perl > /dev/null ; done

real    0m15,932s
user    0m11,344s
sys     0m0,564s

# test_bash:

id="${1:-0e11}"
while IFS=\0 read line
do
    if [[ "$line" =~ ^$id[[:space:]].* ]]
    then
        echo "$line"
        p=1
        continue
    fi
    if [ "$p" = 1 ] && [[ "$line" =~ ^[[:space:]] ]]
    then
        echo "$line"
    fi
    if [[ "$line" =~ ^[^[:space:]] ]] && [ "$p" = 1 ]
    then
        exit 0
    fi

done  < /usr/share/misc/pci.ids

Regards,

[toc] | [prev] | [next] | [standalone]


#176340

FromFloris <jkfloris@dds.nl>
Date2017-01-05 21:10 +0100
Message-ID<sWmwi-7Lg-31@gated-at.bofh.it>
In reply to#176336
Op Thu, 05 Jan 2017 18:13:41 +0100 schreef Javier Barroso  
<javibarroso@gmail.com>:

> Hello,
>
>
> On Thu, Jan 5, 2017 at 6:00 PM, Floris <jkfloris@dds.nl> wrote:
>> Op Wed, 04 Jan 2017 17:27:55 +0100 schreef Floris <jkfloris@dds.nl>:
>>
>>
>>> (Not really a Debian question, but I know there are smart people on  
>>> this
>>> list.)
>>>
>>> I want to search the pci.ids file (from the pciutils package) for all
>>> Compaq devices.
>>> Pci ID's 0e11:xxxx , 1032:xxxx and 10da:xxxx matches Compaq.
>>> Unfortunately, only at a beginning of a list the id of the vendor is  
>>> printed
>>> in column 1. The id of the devices are printed in column 2, with an  
>>> empty
>>> first column.
>>>
>>> (part of pci.ids)
>>> ...
>>> 0e11  Compaq Computer Corporation
>>>         0001  PCI to EISA Bridge
>>>         0002  PCI to ISA Bridge
>>>         0046  Smart Array 64xx
>>>                 0e11 4091  Smart Array 6i
>>>                 0e11 409a  Smart Array 641
>>>                 0e11 409b  Smart Array 642
>>>                 0e11 409c  Smart Array 6400
>>>                 0e11 409d  Smart Array 6400 EM
>>>         0049  NC7132 Gigabit Upgrade Module
>>>         004a  NC6136 Gigabit Server Adapter
>>> ...
>>>         c000  Remote Insight Lights-Out Edition
>>>         f130  NetFlex-3/P ThunderLAN 1.0
>>>         f150  NetFlex-3/P ThunderLAN 2.3
>>> 0e55  HaSoTec GmbH
>>> ...
>>>
>>> Is there an awk, grep and or sed solution?
>>>
>>> Floris
>>>
>>
>> an other solution would be something like:
>>
>> # cat pci.ids | {magic-command} 0e11:004a
>> NC6136 Gigabit Server Adapter
>>
>> what is the magic command?
>
> Using perl:
>
> perl -ne 'print if (/^0e11/.../^\S/) and (/^\s/) or (/^0e11/);'
> /usr/share/misc/pci.ids
>

Thanks! But I prefer a solution with "essential" Debian software/ packages

Floris

[toc] | [prev] | [standalone]


Back to top | Article view | linux.debian.user


csiph-web