|
korn shell "loops & arrays"
Hi,
I am trying to write a script which will loop until a certain action has been performed. I have two files i would like to compares.
For example:
file1 has a list of user ids (about 900) from the company's e-mail server.
file2 has a list of user ids (about 50 or so) from /etc/passwd.
I have file1 in a array, I'd like to have file2 in a loop.
When the id matches it will be redirected the output to /dev/null ,
but when the two ids do not match, I need to redirected the output to file3. This is so I can delete user that have moved on.
This was my 1st try.
#!/usr/bin/ksh
set -A array file1
for i in ${array[@]}
do
echo "==== $i vs file2 ===="
diff $i file2
done > file3
------------------------------------------
and my 2nd try.
#!/usr/bin/ksh
egrep -if file2 file1 > tmp_name
egrep -ivf tmp_name file2 > file3
rm tmp_name
-------------------------------------------
and then:
#!/usr/bin/ksh
while read username
do
while read file2
do
if [ '$file1' = '$file2' ]; then
else
if
done < file2
done < file1
|