in reply to Need to return the first occurance of a search
I have been trying grep and regular expresions, but my regex is not up to solving this particular problem.What in particular did you try, and what didn't work? Effort demonstrated through posted code is generally taken as a sign of good faith.
It's fairly simple to test for the existence of a particular string, say cups-1.5.2-9.fc16.x86_64, but what is your intended behavior when the version number changes? My solution might look something like
perl -e '@arr=`rpm -qa`; if (grep /^cups-\d/, @arr) {print grep /^cups +-\d/, @arr} elsif (grep /^cups-/, @arr) {print "Empty set\n"}'
Expanding it to handle other leading strings would be easy, though in the general case you may want to escape the string, e.g. /^\Q$name\E-\d/
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
|
|---|