Hi Folks
I need help about a script.
Here are the detail of of Script.
I have total 3 files which have following records.
1. file1 -> contains all userids
2. file2 -> random userids, some are present and some are not.
3. file3 -> ls /home file, whever directories they have that is mentioned in file3.
Now my target is that.
I want to compare file3 records with file2, what userids are same, show them, and also show user which userids are not present in file3.
I also want to search file3 userids against file2, if records find then match those userids with file1.
I am doing this with array, startup thing done, but dont understand the point how to search records in array and achieve that task.
Below is my script ..............................................
#!/bin/bash
filename=p1
filename1=p2
declare -a array1
declare -a array2
declare -a array3
array1=( `cat "$filename"`) # Loads contents
array2=( `cat "$filename1"`) # Loads contents
array3=( `ls /home/`)
element_count1=${#array1[*]}
echo $element_count1
element_count2=${#array2[*]}
echo $element_count2
element_count3=${#array3[*]}
echo $element_count3
sleep 3
number_of_elements=${#array1[@]}
number_of_elements1=${#array2[@]}
number_of_elements2=${#array3[@]}
echo '- ARRAY-1--------------------------------'
#echo "Number of elements: 4" # Hard-coded for illustration.
for (( i = 0 ; i < number_of_elements ; i++ ))
do
echo "Element [$i]: ${array1[$i]}"
done
echo '- ARRAY-2-----------------------------------'
#echo "Number of elements: 4" # Hard-coded for illustration.
for (( i = 0 ; i < number_of_elements1 ; i++ ))
for (( i = 0 ; i < number_of_elements1 ; i++ ))
do
echo "Element [$i]: ${array2[$i]}"
done
echo '- LIST OF DIR ------------------------'
#echo "Number of elements: 4" # Hard-coded for illustration.
for (( i = 0 ; i < number_of_elements2 ; i++ ))
do
echo "Element [$i]: ${array3[$i]}"
done
I am waiting for your answer