[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

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



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


Reply to: