![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Development Releases: Linux Mint 4.0 Beta "Fluxbox", 4.0 Alpha "Debian" | iBot | UNIX and Linux RSS News | 0 | 01-04-2008 03:00 PM |
| Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" | Lokesha | UNIX for Dummies Questions & Answers | 4 | 12-20-2007 01:52 AM |
| No utpmx entry: you must exec "login" from lowest level "shell" | peterpan | UNIX for Dummies Questions & Answers | 0 | 01-18-2006 04:15 AM |
| Find -name "*.txt" in Korn Shell Script | jwperry | Shell Programming and Scripting | 3 | 07-19-2002 12:51 PM |
| Korn shell "select" command | mpegler | Shell Programming and Scripting | 2 | 06-23-2002 09:41 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
||||
|
i guess i don't know what it is.
my thought of an array was a way to use multiple values for one variable name. well, I wanted to use your code of reading 2 files (lists) and using the variables on a conditional basis to print a message. (won't go any further, due to cross-posting). ok, so in this part: Code:
i=0
exec < file1
while read array[i] ; do
((i=i+1))
done
My confusion is with this part: Code:
exec <file2
while read entry ; do
i=0
found=0
while ((i<${#array[@]})) ; do
if [[ $entry = ${array[i]} ]] ; then
found=1
break
((i=i+1))
fi
done
if ((found)) ; then
echo $entry is in file1
else
echo $entry is not in file1
fi
done
Are you saying do .. while "i" is less than the value of array[@]? Thanks for any input. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|