awk '/regex/ {awk code}'

Here's a shell script that I put together call whatrpm.sh as in "whatrpm put that file on my 'puter". It shows a string being passed to awk and used as a search pattern. I append a "$" to the string that the user passes on the command line so that it only matches where the filename appears at the end of a line. (it won't work for partial file names and will trip up if the string matches the info data, but you get the idea).


P.

--

case $# in
1)
  search=`echo $1\$`
 ;;
*)
  printf "Usage: $0 <filename>\n" 1>&2
  exit
 ;;
esac


rpm -q -a -i -l | awk --assign search=$search ' /Name :/ { PRODUCT=$3} $0 ~ search { printf("Rpm:%s, File:%s\n",PRODUCT,$0) }' -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Reply via email to