Sponsored Content
Top Forums Shell Programming and Scripting Help with displaying difference between two arrays (Bash) Post 302582857 by Azrael on Sunday 18th of December 2011 10:51:51 PM
Old 12-18-2011
Here's more of the code. Hopefully that will help.

Code:
#!/bin/bash

repeat()
{
   for i in "${files[@]}"
   do

     md5two+=( "$(md5sum $i | awk '{ print $1 }' )" )

   done
 
}

diff(){
  awk 'BEGIN{RS=ORS=" "}
       {NR==FNR?a[$0]++:a[$0]--}
       END{for(k in a)if(a[k])print k}' <(echo -n "${!1}") <(echo -n "${!2}")
}

result()
{
   # Declare two associative arrays
   declare -A temp1 temp2


        for element in "${md5one[@]}"
        do
                ((temp1[$element]++))
        done

        for element in "${md5two[@]}"
        do
                ((temp2[$element]++))
        done

        for element in "${!temp1[@]}"
        do
                if [[ ${temp1[$element]} > 1 && ${temp2[$element]} > 1 ]]
                then
                        unset "temp1[$element]" "temp2[$element]"
                fi
        done

        Array3=($(diff temp1[@] temp2[@]))
        #echo -e "${Array3[@]}"
 
}
 
display(){
   clear
   echo -e "It should be here right?\n\n"
   diff
   echo -e '\a'
   echo -e "${Array3[@]}"

}
 
# Make sure user is logged in as root
if [[ $EUID -ne 0 ]]; then

   echo "This script must be run as root" 1>&2
   exit 1

fi

# Get names of all modules
files=`find / -name "*.ko"` >> /tmp/mod0

# Read names of modules from temp file into array
while read line ;
do
        FILEZ[$files]="$line"
        files=$(($files+1))

done < /tmp/mod0

rm /tmp/mod0

# Get md5 hashes of all modules on the system and put them in an array
for i in "${files[@]}"
do

     md5one+=( "$(md5sum $i | awk '{ print $1 }' )" )

done

# Forever loop to keep monitoring constant
for ((  ;  ; ))
do
        repeat

        if [[ ${md5one[@]} == ${md5two[@]} ]]; then

                md5two=( )
        else
                monitor
                md5one=( )
                md5one=("${md5two[@]}")
                md5two=( )
        fi

done

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Arrays in bash.need help

:confused: Is it possible to delete array elements dynamically.For instance,consider an array( a b c d ) ,now can i delete array (the third element 'c').So that the array becomes array(a b d).. Thanks in advance!! (1 Reply)
Discussion started by: tj23
1 Replies

2. Shell Programming and Scripting

arrays in bash

hi guys, i have the following script and when i run it i get blank lines on the screen.. i am trying to display the contents of array var.. #!/usr/bin/bash var=`awk 'NR>20&&NR<31' try.sum | awk '{print $4}'` echo "${var}" (1 Reply)
Discussion started by: npatwardhan
1 Replies

3. Shell Programming and Scripting

arrays and while loops in bash

hi guys, i have an array called ARRAY which has elements in it... i am trying to assign elements of ARRAY to master_array.. i get a =: command not found error.. i=0 while do ${master_array}=${ARRAY} ((i++)) done is there something i am missing? (4 Replies)
Discussion started by: npatwardhan
4 Replies

4. Shell Programming and Scripting

Compute difference between 2 arrays perl

Hi, I have 2 arrays. I have to compute symmetric difference! @arr=qw(19205134 18630215 18453487 18416242 18338715 18227590 17698645); @arr1=qw(18227590 18053561 17698645 16966777); #The code which i used is this! @union = @isect = @diff = (); %union = %isect = (); %count =... (3 Replies)
Discussion started by: vanitham
3 Replies

5. Shell Programming and Scripting

How to find difference between two arrays in Perl?

Hi, Could someone please help me with this? I have two arrays and I need to generate third array containing difference between the two. For example - @Array1 = ; @Array2 = ; I would like to find difference between these two and generate third array that contains the difference. In... (5 Replies)
Discussion started by: sncoupons
5 Replies

6. Shell Programming and Scripting

PHP Compare 2 Arrays find difference & case insensitive

Hi, I need an elegant solotion in php. I need to compare 2 arrays (array1 & array2), to find all instances of array 2 which is not in array1. I don't want to see any instances of array1 wich is not in array2 (here "the") Array1: This, is, the, data, of, array1 Array2: this, is, data, Of,... (2 Replies)
Discussion started by: lowmaster
2 Replies

7. Shell Programming and Scripting

Difference between 2 arrays in perl

Hi, I have 2 arrays: @a=qw(19190289 18381856 12780546 10626296 9337410 8850557 7740161 8101063); @b=qw(18309897 17612870 10626296 16871843 7740161 19947571 18062861); $len=@a; print "<br> length of array1: $len<br>"; $len1=@b; print "<br> length of array2: $len1<br>"; The output... (3 Replies)
Discussion started by: vanitham
3 Replies

8. Shell Programming and Scripting

Displaying difference of 2 files

Hi All, Got this 2 file namely a.txt and b.txt, i want to know how to extract the difference between the two files, the output will be written to a file. e.g. >>a.txt<< Nokia 1100 Nokia 1200 Nokia 1300 Nokia 1400 Nokia 1500 Nokia 1600 Nokia 1700 Nokia 1701 Nokia 1702 Sagem 1100... (3 Replies)
Discussion started by: shtobias
3 Replies

9. Shell Programming and Scripting

bc,getopt and arrays in bash

trying to sum elements in an array using bc and getopt,i have a file with names and thier vaules if the names appears 3 times i should multiply its value with 3 then find the sum of all the elements together cat foo.txt max 2.3 henry 3 fransis 4.5 max 2.3 henry 3 max 2.3 it should... (1 Reply)
Discussion started by: elginmulizwa
1 Replies

10. Shell Programming and Scripting

Using arrays in bash using strings to bash built-in true

I have the following code and for some reason when I call the program using /home/tcdata/tatsh/trunk/hstmy/bin/bash/raytrac.bash --cmod=jcdint.cmod I get hasArgument = hasArgument = true Somehow the array element is returning even though I have not chosen the option. ... (41 Replies)
Discussion started by: kristinu
41 Replies
All times are GMT -4. The time now is 03:01 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy