09-15-2007
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
10 More Discussions You Might Find Interesting
1. Solaris
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
- 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
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
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
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
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
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
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
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
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
LEARN ABOUT PHP
array_replace_recursive
ARRAY_REPLACE_RECURSIVE(3) 1 ARRAY_REPLACE_RECURSIVE(3)
array_replace_recursive - Replaces elements from passed arrays into the first array recursively
SYNOPSIS
array array_replace_recursive (array $array1, array $array2, [array $...])
DESCRIPTION
array_replace_recursive(3) replaces the values of $array1 with the same values from all the following arrays. If a key from the first array
exists in the second array, its value will be replaced by the value from the second array. If the key exists in the second array, and not
the first, it will be created in the first array. If a key only exists in the first array, it will be left as is. If several arrays are
passed for replacement, they will be processed in order, the later array overwriting the previous values.
array_replace_recursive(3) is recursive : it will recurse into arrays and apply the same process to the inner value.
When the value in $array1 is scalar, it will be replaced by the value in $array2, may it be scalar or array. When the value in $array1 and
$array2 are both arrays, array_replace_recursive(3) will replace their respective value recursively.
PARAMETERS
o $array1
- The array in which elements are replaced.
o $array2
- The array from which elements will be extracted.
o $...
- Optional. More arrays from which elements will be extracted.
RETURN VALUES
Returns an array, or NULL if an error occurs.
EXAMPLES
Example #1
array_replace_recursive(3) example
<?php
$base = array('citrus' => array( "orange") , 'berries' => array("blackberry", "raspberry"), );
$replacements = array('citrus' => array('pineapple'), 'berries' => array('blueberry'));
$basket = array_replace_recursive($base, $replacements);
print_r($basket);
$basket = array_replace($base, $replacements);
print_r($basket);
?>
The above example will output:
Array
(
[citrus] => Array
(
[0] => pineapple
)
[berries] => Array
(
[0] => blueberry
[1] => raspberry
)
)
Array
(
[citrus] => Array
(
[0] => pineapple
)
[berries] => Array
(
[0] => blueberry
)
)
Example #2
array_replace_recursive(3) and recursive behavior
<?php
$base = array('citrus' => array("orange") , 'berries' => array("blackberry", "raspberry"), 'others' => 'banana' );
$replacements = array('citrus' => 'pineapple', 'berries' => array('blueberry'), 'others' => array('litchis'));
$replacements2 = array('citrus' => array('pineapple'), 'berries' => array('blueberry'), 'others' => 'litchis');
$basket = array_replace_recursive($base, $replacements, $replacements2);
print_r($basket);
?>
The above example will output:
Array
(
[citrus] => Array
(
[0] => pineapple
)
[berries] => Array
(
[0] => blueberry
[1] => raspberry
)
[others] => litchis
)
SEE ALSO
array_replace(3), array_merge_recursive(3).
PHP Documentation Group ARRAY_REPLACE_RECURSIVE(3)