Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!sdd.hp.com!decwrl!ogicse!iwarp.intel.com!news From: merlyn@iwarp.intel.com (Randal Schwartz) Newsgroups: comp.unix.questions Subject: Re: Cshell question: taking wordlists as a single string Message-ID: <1990Aug16.065917.3671@iwarp.intel.com> Date: 16 Aug 90 06:59:17 GMT References: <3251@syma.sussex.ac.uk> Sender: news@iwarp.intel.com Reply-To: merlyn@iwarp.intel.com (Randal Schwartz) Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 51 In-Reply-To: andy@syma.sussex.ac.uk (Andy Clews) In article <3251@syma.sussex.ac.uk>, andy@syma (Andy Clews) writes: | I have a Csh script called "whatnews" which takes words as arguments and | searches the file /usr/lib/news/newsgroups for lines containing any one | of those words, the requirement being to show users what newsgroups are | there that may be something to do with the searched word. It is not | case sensitive (i.e. it uses fgrep -i) | | whatnews biology | | "whatnews" then proceeds to show me all lines in /usr/lib/news/newgroups | that contain the string "biology". If several words are supplied as a | list, whatnews searches the file for each of these words. The | difficulty arises because I want to do (for example) | | whatnews "bug reports" | | where the intended effect is to search out all lines containing the | string "bug reports". At the moment it splits this up into "bug" and | "reports" and does two searches. This is because the script contains a | foreach i ($*) | loop for repeated searches. Quoting (single or double) doesn't help. | | Basically, then, can Cshell cope with word-lists as single arguments, or | must I write a C program to do the job (or try sh or ksh?) | | No joy as yet with TFM. Any help appreciated; email probably best. I | will summarise if possible. Thanks for listening. Well, you can try this Perl script: ================================================== snip snip #!/usr/bin/perl for (@ARGV) { s/\W/\\$1/g; # de-magicize $all .= "$_|"; # and create regular-expression } chop($all); # remove last "|" open(G,"/usr/lib/news/newsgroups") || die "Cannot open newsgroups: $!"; while () { print if /$all/io; } close(G); ================================================== snip snip Untested, but it should do the job. -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/