Re: Piping within for-loops
From: Barry Margolin (barmar_at_alum.mit.edu)
Date: 02/27/05
- Next message: Christophe C: "csh : PATH not set in SOME non-interactive sessions"
- Previous message: Michael Heiming: "Re: Need help for comparing file types from test and prodcution database"
- In reply to: halsbrecherisch: "Piping within for-loops"
- Next in thread: Ed Morton: "Re: Piping within for-loops"
- Reply: Ed Morton: "Re: Piping within for-loops"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 ***
- Next message: Christophe C: "csh : PATH not set in SOME non-interactive sessions"
- Previous message: Michael Heiming: "Re: Need help for comparing file types from test and prodcution database"
- In reply to: halsbrecherisch: "Piping within for-loops"
- Next in thread: Ed Morton: "Re: Piping within for-loops"
- Reply: Ed Morton: "Re: Piping within for-loops"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|