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 and shell scripting languages 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 11:35 AM
Size of an array in sh shell script trivektor Shell Programming and Scripting 1 09-29-2006 12:01 AM
difference between AIX shell scripting and Unix shell scripting. haroonec Shell Programming and Scripting 2 04-12-2006 09:12 AM
korn shell array? cstovall Shell Programming and Scripting 5 01-28-2005 05:40 PM
Oracle To Korn Shell Array kdst UNIX for Advanced & Expert Users 1 09-24-2002 10:21 AM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 03-09-2008
learnbash learnbash is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 96
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
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:48 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0