Sponsored Content
Top Forums Shell Programming and Scripting Array Declaration and For Loop Post 302136122 by 33junaid on Saturday 15th of September 2007 07:37:50 AM
Old 09-15-2007
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.
 

10 More Discussions You Might Find Interesting

1. Solaris

i cannot give array declaration in shell script

Dear all, i m unable to give array decalartion in solaris Operating system shell script and script was so.sh declare -a bull for i in 1 2 3 4 5 6 7 8 9 do bull=$i echo "${bull}" done it is throwing an error called so.sh: declare: not found so.sh: bull=1: not... (20 Replies)
Discussion started by: naree
20 Replies

2. Shell Programming and Scripting

How to use array values after the loop.

- I m retreving values from database and wish to use those values later in my shell script. I m placing these values in an array da_data but outside loop array is empty.Problem is its treating array as local inside loop hence array is empty outside loop. Plz go through the script and suggest how... (1 Reply)
Discussion started by: Devesh5683
1 Replies

3. Shell Programming and Scripting

Help with awk in array in while loop

Hi everyone:) I have 2 files - IN & OUT. Example: IN A:13:30 B:45:40 . . . UNLIMITED OUT Z:12:24 Y:20:15 . . . UNLIMITED I want first row of numbers of IN - OUT. Example 13-12 45-20 My code is (2 Replies)
Discussion started by: vincyoxy
2 Replies

4. UNIX for Dummies Questions & Answers

Array declaration problem

Hi all, I would like to declare a vector of variables and access them sequentially. Here is my code ARRAY_CT="0001000000 0000100000 0000010000" ELEMENTS_CT=${#ARRAY_CT} echo $ELEMENTS_CT for (( j=1;j<=$ELEMENTS_IS;j++)); do echo ${ARRAY_IS} done ... (2 Replies)
Discussion started by: f_o_555
2 Replies

5. Shell Programming and Scripting

Array declaration in Shell script

this is my code declare -a USERCERT declare -a CACERT declare -a KEYSRC this is the error + declare -a USERCERT ./clone.sh: 1: declare: not found + declare -a CACERT ./clone.sh: 1: declare: not found + declare -a KEYSRC ./clone.sh: 1: declare: not found (11 Replies)
Discussion started by: xerox
11 Replies

6. Shell Programming and Scripting

Array with do while and if loop

Hi All, I am trying to run a do while for an array. And in the do while, I'm trying to get a user response. Depending on the the answer, I go ahead and do something or I move on to next element in the array. So far I can read the array, but I can't get the if statement to work. Any suggestions... (5 Replies)
Discussion started by: nitin
5 Replies

7. Shell Programming and Scripting

Array Variable being Assigned Values in Loop, But Gone when Loop Completes???

Hello All, Maybe I'm Missing something here but I have NOOO idea what the heck is going on with this....? I have a Variable that contains a PATTERN of what I'm considering "Illegal Characters". So what I'm doing is looping through a string containing some of these "Illegal Characters". Now... (5 Replies)
Discussion started by: mrm5102
5 Replies

8. Shell Programming and Scripting

Loop over array in batches

given an array of filenames files=(*) how can i loop over these in batches of four, or even better, work always with four files simultaneously. i want do something with these files, always four of them simultaneously, and if one is ready the next should start. one idea, but definitely not... (2 Replies)
Discussion started by: dietmar13
2 Replies

9. Shell Programming and Scripting

Global declaration of Array in Shell

Hi, Have assigned values in Array and iterating in while loop and would require values outside of the loop. But its returning NULL. could you please help us how to define Global array declaration in Unix shell scripting? i am using Kron shell. Thanks in advance. (2 Replies)
Discussion started by: periyasamycse
2 Replies

10. Shell Programming and Scripting

awk loop using array:wish to store array values from loop for use outside loop

Here's my code: awk -F '' 'NR==FNR { if (/time/ && $5>10) A=$2" "$3":"$4":"($5-01) else if (/time/ && $5<01) A=$2" "$3":"$4-01":"(59-$5) else if (/time/ && $5<=10) A=$2" "$3":"$4":0"($5-01) else if (/close/) { B=0 n1=n2; ... (2 Replies)
Discussion started by: klane
2 Replies
ARRAY_UINTERSECT_UASSOC(3)						 1						ARRAY_UINTERSECT_UASSOC(3)

array_uintersect_uassoc  -  Computes  the intersection of arrays with additional index check, compares data and indexes by separate callback func-
tions

SYNOPSIS
array array_uintersect_uassoc (array $array1, array $array2, [array $...], callable $value_compare_func, callable $key_compare_func) DESCRIPTION
Computes the intersection of arrays with additional index check, compares data and indexes by separate callback functions. PARAMETERS
o $array1 - The first array. o $array2 - The second array. o $value_compare_func - The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second. int callback (mixed $a, mixed $b) o $key_compare_func - Key comparison callback function. RETURN VALUES
Returns an array containing all the values of $array1 that are present in all the arguments. EXAMPLES
Example #1 array_uintersect_uassoc(3) example <?php $array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red"); $array2 = array("a" => "GREEN", "B" => "brown", "yellow", "red"); print_r(array_uintersect_uassoc($array1, $array2, "strcasecmp", "strcasecmp")); ?> The above example will output: Array ( [a] => green [b] => brown ) SEE ALSO
array_uintersect(3), array_intersect_assoc(3), array_intersect_uassoc(3), array_uintersect_assoc(3). PHP Documentation Group ARRAY_UINTERSECT_UASSOC(3)
All times are GMT -4. The time now is 02:15 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy