Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Checking for dups

5,888 views
Skip to first unread message

Wade Williams

unread,
May 11, 1995, 3:00:00 AM5/11/95
to
I'm working on a script to add email aliases to my aliases file, given
a Comma separated list.

I've got an awk script which formats each address correctly, and then
puts it into a temporary file. I then want to check each entry in
that file against my aliases file.

The temp file looks like:

wwil...@mail.state.tn.us
jne...@mail.state.tn.us
jwa...@mail.state.tn.us

My thinking was to pass each one of those to grep. If grep returns
not found, I can safely add that one to the aliases file without fear
of creating a duplicate address.

However, I can't just cat the file to grep because it would cause grep
to blow up with a "too many parameters" error.

So, what I need is to cat the file one line at a time and use that as
my search parameter for grep. However, I can't find a way to cat a
file one line at a time. I think it's probably possible to do somehow
using ed.

So, the script will look like this:

1. Use awk script to process input file and write correctly formatted
addressed to a temp file.

2. One at a time, pass each line of the temp file to grep. Grep
searches /usr/lib/xaliases. If grep returns 1, add the address to
the xaliases file. If it returns 0, log an error to an error file.

Can anyone give me some guidance on how to accomplish this task? I'm
sure the answer is simple.

Thanks,

Wade Williams
wwil...@mail.state.tn.us


Parris Geiser

unread,
May 12, 1995, 3:00:00 AM5/12/95
to

> wwil...@mail.state.tn.us
> jne...@mail.state.tn.us
> jwa...@mail.state.tn.us

> Thanks,

> Wade Williams
> wwil...@mail.state.tn.us

Why not just cp the xaliases file to a tmp file,
add the new stuff
do a sort -u into another file which becomes the new xaliases file.
if you want to log dups just diff the above files.
parris

Chris Gesler

unread,
May 17, 1995, 3:00:00 AM5/17/95
to
In korn shell (perhaps others), to "cat a file one line at a
time" I use something like the following:

for i in `cat file.name` (be sure these are back ticks)
do
your grep statement here, using $i for the arg
done

The loop is self-limiting. The only problem is, the read is of
one field only, so if each line in your file is more than one
field (it doesn't look like your current example is), each $i
will only be part of the line. You will probably have to use
double quotes around the variable name in the grep statement
(i.e., "$i") because of the periods in your argument field.

Hope this helps --Chris.

--
Chris Gesler, Unix System Administrator
Priority Health, Grand Rapids, MI
7342...@compuserve.com

Steve G Parker

unread,
May 17, 1995, 3:00:00 AM5/17/95
to
Chris Gesler (7342...@CompuServe.COM) wrote:
: In korn shell (perhaps others), to "cat a file one line at a

: Hope this helps --Chris.

I missed the original posting, but if you are wanting to get consecutive
lines from a file, then :

while i=`line`
do
echo "i is set to $i"
done < my_file

will process each line in turn, so from my_file containing :
Hello this is
a test file
Each line has a number of
words in it, but i is set
to the whole line

the output would be :
i is set to Hello this is
i is set to a test file
etc.

Steve

--
____________________________ Steve Parker ______________________________
/ SVCC at ICL BRA01 phone 7263 x2916 OfficePOWER S.G.Parker-bra0101 \
| external phone (01344) 472916 |
\________________ internet st...@bra01.icl.co.uk ________________________/

### DISCLAIMER : Any opinions expressed herein are entirely my ###
### own and not necessarily those of ICL or any other organisation. ###

Chris Gesler

unread,
May 19, 1995, 3:00:00 AM5/19/95
to
Steve: Thanks. You can never stop learning in this game and I
have encountered countless situations where I could have used
your suggestion. I'm glad to add it to my bag of tricks! --CG

Heiner Steven

unread,
May 23, 1995, 3:00:00 AM5/23/95
to
s...@oasis.icl.co.uk (Steve G Parker) wrote:

[...]


> I missed the original posting, but if you are wanting to get
> consecutive lines from a file, then :
>
> while i=`line`
> do
> echo "i is set to $i"
> done < my_file

What is the advantage over

while read i


do
echo "i is set to $i"
done < my_file

? This loop uses no external program (line), and is understood
by all sh dialects (sh/ksh/bash/...)

Heiner

------------------------------------------------------
/ Heiner Steven hei...@hsysnbg.nbg.sub.org /
/ World, Europe, Germany, Bavaria, Nuernberg /
------------------------------------------------------
ZZW:q!!xx^K^DYES^MQXexit^Mquit^M^C^C^?Qq^[xxxalles kacke


Steve G Parker

unread,
May 28, 1995, 3:00:00 AM5/28/95
to
Heiner Steven (hei...@hsysnbg.nbg.sub.org) wrote:
: s...@oasis.icl.co.uk (Steve G Parker) wrote:
: > while i=`line`

: > do
: > echo "i is set to $i"
: > done < my_file

: What is the advantage over
: while read i
: do
: echo "i is set to $i"
: done < my_file


: Heiner

None at all, so far as I know... thanks for the tip.

Brian Foster

unread,
Jun 1, 1995, 3:00:00 AM6/1/95
to
Steve G Parker (s...@oasis.icl.co.uk) wrote:
| Heiner Steven (hei...@hsysnbg.nbg.sub.org) wrote:
| : s...@oasis.icl.co.uk (Steve G Parker) wrote:
| : > while i=`line`
| : > do
| : > echo "i is set to $i"
| : > done < my_file
| :
| : What is the advantage over
| : while read i
| : do
| : echo "i is set to $i"
| : done < my_file
|
| None at all, so far as I know... thanks for the tip.

there are a few differences. e.g., try inputting a line
ending with backslash ("\"), such as:

first line \
second line

the read i version reads both lines into one instance of
$i (sans the escaping backslash: "first line second line").
but the `line` version executes twice, first reading the
backslash-ending line (with the backslash) into an instance
of $i ("first line \"), and the second time 'round the loop
the subsequent line into $i ("second line").

another difference: leading spaces/tabs are stripped in
the read i version (at least in some versions of various
shells; i cannot recall if all shells have always done this
or not).

disclaimer: my opinions are mine!
--
"Girls who hear voices inside their heads | Brian Foster, SGS-Thomson, c/o PACT
have only two options: they can raise | b...@pact.srf.ac.uk Bristol
armies and drive the English out of | (+44 or 0)117 9707 156 England
Aquitaine, or they can seek professional | http://www.pact.srf.ac.uk
help." -Tom Holt, _Here_Comes_the_Sun_, Orbit 1993/4, ISBN 1-85723-187-2

0 new messages