Array Declaration and For Loop

I am just stucked in syntax.This is more like a array and for loop problem.

I want to use ls -l command and get filezise and filename of all filenames in the directory in an array (say array#1).
After 2 minutes of sleep, i want to get the same information in another array (say array#2).

The command ls -l | awk '{print $9 " " $5}' prints all the filenames and then space and then the filezise of that file. I want to compare each array value and then get those filenames which have same size in both arrays.

For example:
Declare Array1......
>ls -l | awk '{print $9 " " $5}'
File1 Size1 (copy this value in array1[0])
File2 Size2 (copy this value in array1[1])
File3 Size3 (copy this value in array1[2])
FileN SizeN (copy this value in array1[N])

After sleep 120, make another array called array2 and then
Declare array2.......
>ls -l | awk '{print $9 " " $5}'
File1 Size1 (copy this value in array2[0])
File2 Size2 (copy this value in array2[1])
File3 Size3 (copy this value in array2[2])
FileN SizeN (copy this value in array2[N])

May be we can get new files after 2 minutes but we have to get all the rows in it.

Then using a for loop, compare each value of array1 with array2 and where array1 value=array2 value, I have to get the value of array1 first argument (i.e. File name itself not the whole string which will include the filesize which is seperated by space).

Please convert this to correct synatx in shell.Thanks.

With zsh, bash, ksh93 and without arrays,
you could write something like this:

first="$(grep -v ^total <(ls -s))"
sleep ....
read< <(grep  -f <(echo "$first") <(ls -s));echo "${REPLY#* }"

it is not giving the correct result....where is the filesize in first variable?

In the first column:

zsh 4.3.4% first="$(grep -v ^total <(ls -s))"
zsh 4.3.4% echo "$first"
2256 abs-guide.pdf
   4 Desktop
   0 Examples
   4 images

What's wrong with the result you get?

I just wrote this script and is working very fine:

#!/bin/bash

counter1=0
for i in `ls -ltr | grep -v "total" | grep -v "pre_swh" | awk '{ print $9 ":" $5 }'`;
do

			arr\_key_old[$counter1]=$i
			
							
			echo "Counter1 is  $counter1 "
			echo "Key Old is : $\{arr\_key_old[$counter1]\} "
			
			counter1=\`expr $counter1  \+ 1\`

done

echo "Before sleeping"
sleep 120
echo "After sleeping"

counter2=0

for i in `ls -ltr | grep -v "total" | grep -v "pre_swh" | awk '{ print $9 ":" $5 }'`;
do

			arr\_key_new[$counter2]=$i
			
							
			echo "Counter2 is  $counter2 "
			echo "Key new is : $\{arr\_key_new[$counter2]\} "
			
			counter2=\`expr $counter2  \+ 1\`

done

counter3=1
for j in `echo ${arr_key_old[*]}`
do

for k in \`echo $\{arr\_key_new[*]\}\`
do
		
	if [ "$j" = "$k" ]
	then
		echo " Here testing for old and new : $j is equal to $k"
		file_name=\`echo $j|awk -F':' '\{ print $1 \}'\`
		echo "$counter3 Final file name is $file_name"
		counter3=\`expr $counter3  \+ 1\`
	fi
done

done