The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Simple Array in Ksh Scripting ravikirankethe UNIX for Dummies Questions & Answers 2 11-01-2006 07:35 AM
Size of an array in sh shell script trivektor Shell Programming and Scripting 1 09-28-2006 08:01 PM
difference between AIX shell scripting and Unix shell scripting. haroonec Shell Programming and Scripting 2 04-12-2006 05:12 AM
korn shell array? cstovall Shell Programming and Scripting 5 01-28-2005 01:40 PM
Oracle To Korn Shell Array kdst UNIX for Advanced & Expert Users 1 09-24-2002 06:21 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-09-2008
Registered User
 

Join Date: Mar 2008
Posts: 37
Smile Array Help in shell scripting

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
Reply With Quote
Google UNIX.COM
Forum Sponsor
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:05 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0