Random ramblings

All | General | Motorbikes | Networking | Odds & Sods | Soapbox | Solaris
« Where's all the oil... | Main | Quagga 0.98.3 releas... »
20050401 Friday April 01, 2005

awk pedantry

Jason Salkeld blogged about how to find the package a file belongs to and included this command:

grep /usr/sbin/fuser /var/sadm/install/contents | awk '$2 ~ /^f$/ {print $NF}'

Two problems:

  1. as someone else already noted, grep piped to awk is redundant.
  2. Using a regex for an absolute match on a field is overkill

The following would be more efficient (well, notionally at least... ;) ):

awk '$1 == "/usr/sbin/fuser" && $2 == "f" { print $NF }' /var/sadm/install/contents

Note that the above assumes that awk is either a shell alias for or that the executable is a symlink to either GNU Awk or nawk. (GNU Awk appears to be the more efficient of the two, for this command at least).

( Apr 01 2005, 07:00:35 PM IST ) Permalink Comments [0]

Trackback URL: http://blogs.sun.com/paulj/entry/awk_pedantry1
Comments:

Post a Comment:

Name:
E-Mail:
URL:

Your Comment:

HTML Syntax: NOT allowed

Calendar

RSS Feeds

Search

Links

Navigation

Referers