Re: Piping within for-loops

From: Barry Margolin (barmar_at_alum.mit.edu)
Date: 02/27/05


Date: Sun, 27 Feb 2005 09:19:06 -0500

In article <d756f1c9.0502270452.2f902ef@posting.google.com>,
 halsbrecherisch@yahoo.com (halsbrecherisch) wrote:

> Hi!
> I want to write a script, that selects words from a wordlist,
> which don't contain certain characters, e.g.
> # ./filter a b c
> lists all words that don't contain the letters a, b and c.
> I've written this script:
>
> --- begin
> cat /usr/share/dict/words |
>
> for omit in $1
> do
> if [ ! "$omit" == "" ]; then grep -v -i "$omit" ; else cat; fi
> done |
>
> tee result
> --end
>
> My problem is, that the grep only affects the piped data during the 1st
> loop of the for statement. How can I solve this?

Unless you run the script like:

./filter "a b c"

it looks to me like your script will only loop once anyway. Don't you
mean:

for omit in "$@"

?

Anyway, if you want to reread the file each time through the loop, put
the file reading inside the loop:

DICT=/usr/share/dict/words
for omit in "$@"
do
  if [ ! "$omit" == "" ]
  then grep -v -i "$omit" $DICT
  else cat $DICT
  fi
done | tee result

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***


Relevant Pages

  • Re: Report in FM 6 or 7
    ... achieve this report format will have to be done via scripting. ... but they will simplify the script and Sort Order. ... End Loop ... The normal 'Dancer' field is used so that if there are more than one ...
    (comp.databases.filemaker)
  • Re: recreate database script not work
    ... I got a script which is supposed to regenerate database systax. ... REM gen_dbse_9.sql ... end loop; ...
    (comp.databases.oracle.server)
  • Re: Loop Problem (At Least I think)
    ... If there are no images matching the product ... "" Then" statement (the one below the loop, outside of it), is this just ... >> script to finish. ... > 2) Read the database table and acess the dictionary object for the ...
    (microsoft.public.scripting.vbscript)
  • Re: How to set up a global variable in a sub-routine?
    ... the 'global variables' are more like constants ... ... single script, I need a way to tell it only once where the file is and ... So, if you construct a loop with a loop variable, you ... >programmers avoid global variables completely. ...
    (perl.beginners)
  • RE: (Urgent) Create many txt files from tables with DTS Package
    ... when i run this script the error show: ... > How to loop through a global variable Rowset ... >> D.90.70.0002 Husain Djojonegoro BOARD OF COMMISSIONER ... >> D.50.04.0071 Putu Supertama Checker BI ...
    (microsoft.public.sqlserver.dts)