- To: Alexander Samad <alex@xxxxxxxxxxxx>
- Subject: Re: [SLUG] escaping variables in bash
- From: Peter Rundle <prundle@xxxxxxxxxxxxxx>
- Date: Tue, 14 Sep 2004 14:11:50 +1000
- Cc: slug@xxxxxxxxxxx
- User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.2) Gecko/20040803
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) }'