I've been trying to have an array of ip addresses go through a loop one at a time. Then compare if the current element is in another array of ip addresses. I've traced my error with /bin/bash -x
From what I found on Google it seems Bash isn't great at comparing floating point numbers. I saw some suggestions on piping through bc first, but I'm unfamiliar with how that would work here. Perhaps there's also a simpler way.
Here is the code I'm using:
Right now it looks to see if an ip Firefox is connected to is in the "white" array. You may have to refresh your browser to get an ip.
UPDATE: It doesn't seem to be an issue with bc. I tried using the following to get the first ip's and the error persists:
Last edited by Azrael; 12-21-2012 at 06:48 PM..
Reason: New information
It doesn't need to compare floats, it needs to compare strings. As I can't see line 65 (the one with the syntax error) in your code, pls. post entire script and/or log of execution.
Could you tell us what you are trying to do. Not how you want to do it. You have some greatly over-complex code to do something simple - it seems to me.
an awk one-liner and two inputs can identify or remove duplicates, for example.
Sorry, but this is the dichotomy I face in every forum. Posting 200 lines of code and being told that is too much information. Or just putting the problematic code and being told its not enough. I also feared that since some of this will only run on KDE that many would ignore this post, but here goes:
Much of this is commented out as I've made changes where some is now irrelevant, or to not run every part to make testing easier.
What was said about "awk '!x[$0]++'" removing duplicates is true, but this was only for where netstat was being checked. "unset ip" ip was to clear the current ips listed in the ip array to so that the command that checks netstat would not enter the same ips again and cause duplicates in that array.
Its true this does not need to check floats, but strings. I should have specified that. However, I've never told this code to interpret ips as floats or strings as Bash is not a strong typed language. So I don't know how to set or correct this.
I have also tried to resolve checking the elements of the arrays one at a time with a nested for loop. It seemed to be better logic but I run into problems with no output.
Sorry, but this is the dichotomy I face in every forum. Posting 200 lines of code and being told that is too much information. Or just putting the problematic code and being told its not enough.
. . .
Unfortunately the error msg you posted did not relate to the problematic code snippet you gave. So - where to start looking?
Anyhow, seems like bash doesn't really like the dots in the ip numbers, even when comparing strings, in the if [ "$c" == ...]. Try replacing them with a non-bash-irritating separator, which is not that easy to find ( I used a comma):
Hello everyone,
I need help comparing 2 arrays. the first array is static; the second array is not ..
array1=( "macOS Mojave" "iTunes" )
cd /Volumes
array2=( * )
# output of array2
macOS Mojave
iTunes
Mac me
The problem occurs when I compare the arrays with the following code -
... (6 Replies)
I have 2 arrays of values for example
A1 ={10 15 3 21}
A2 ={10 15 3 22}
I need to check which one has greater values. However:
A1 ={10 15 3 21}
A2 ={10 15 3 21 3} - this one would be greater.
A1 ={10 15 5 21} - this one greater
A2 ={10 15 3 21}
Basically, I want to compare patch... (6 Replies)
I have two arrays and they look like this:
array=(`cat /local/mnt/*sys/*includes|grep -v NEW`)
array2=(`cat /tmp/*sys.z |grep -v NEW`)
I am trying to compare them but I need to use the diff -u command. I am not sure how to do this. I cannot just do diff -u ${array} ${array2}
I cannot... (4 Replies)
Basically, I have 2 files with IP address. For example 134.123.3.234 in the first file and 134.123.3.235 in the second. Now I want to create a file with a IP address with IP 134.123.3.236...(max 254). So i have to check files which IP address in previous two files and base on that to create a new... (10 Replies)
Hi,
I am trying to compare two lists that are held in two variables so I believe I need to access the array elements to compare these. I am using ksh 88 and the code I have tried is below:
for file in ${origfilelist}
do
if ]]
then
print -- "File ${file}... (3 Replies)
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)
Hello,
Consider the following 2 arrays:
Array1 = qw(Fa0/0 Fa0/1 Fa0/2 Fa0/3);
Array1 = qw(Fa0/1 Fa0/2 Fa0/3 Fa0/4);
I want to compare the following 2 arrays as follows:
Take specific action when elements of Array1 that doesn't exist in Array2 (in my example: Fa0/0).
Take another... (4 Replies)
I have two arrays I need to compare against a third, looking for matches, not differences. I think I'm going to have to convert the arrays to files and grep them, but I'm not too sure if there's a tool to enable me to matches specifically, instead of differences.
Thanks in advance!
Karl (9 Replies)
Hello,
Let's say that we have the two following arrays
@array1=
@array2=
Is there any easy way to compare these two arrays and print the values that exist in array1 and not in array2 and the values that exist in array2 and not in array1?
Regards,
Chriss_58 (3 Replies)
I want a soultion to compare two arrays in sh with an easy way.I want a solution to synchrose users between different AIX servers where no NIS is available. All users are meant to be same on all 10 servers. So the approach is to consider first server as master user repository and whatever the users... (0 Replies)