Basically I have a file num1 which contains IP addresses
I need to find max element of third number in IP address which is 25! And after that relating to max third number I need to find max fourth number which is 237 (6th line).
I tried to split up IP address in 4 parts such as A B C D... And then I work only with C and D but my code gives me C =2 which is not max ;( D does now work at all ;( Help me please to fix my little piece of code ;( thanks
}~
There are several problems here, including, but not necessarily limited to:
Sorting a file alphanumerically using the entire input line as the only sort key doesn't serve any useful purpose when you're trying to compare numeric values in the 3rd and 4th period separated fields.
Your 1st for loop's do doesn't have a matching done.
The wc -l command in both of your for loops will hang waiting for the user to type in input (since no file operands are given on the command line).
I don't see how counting the number of lines in a file (which is what wc -l does) will be of any use in solving this problem.
In the test command [ $max "$D" > "$lastmax"] you need a space before the closing square bracket.
In both of your test commands, the > operator performs an alphanumeric comparison. You need to use the -gt operator to compare numeric comparisons. (For example the command:
prints:
but the command:
produces no output.)
The scripts that RudiC and I provided before should give you alternative solutions to this problem.
Oops. That was my intention, but I neglected to reset maxoct4, as in Don's corrected version.
Do you want to maximum over all files? Just pass all the filenames to the awk (or sort) command.
I guess i need add smth else .....
Moderator's Comments:
We are serious about using CODE tags. Leaving out the code tags makes the above (poorly formatted single-line) command appear to be a multi-line command with syntax errors.
Last edited by Don Cragun; 10-05-2013 at 05:21 PM..
We are serious about using CODE tags. Leaving out the code tags makes the above (poorly formatted single-line) command appear to be a multi-line command with syntax errors.
No, combining bits and pieces of RudiC's suggested code, and CarloM's (or my corrected version of CarloM's) code gives you a hybrid solution that does runs slower and only considers the contents of one file.
I would still suggest my solution (slightly modified to use your new set of files):
but I may be biased.
Note that if you did want to sort a list of files in the directory /usrs/Manu/files, you would have to leave off the double quotes in the command:
With the command:
it will only sort the single file named * in that directory or produce a file not found diagnostic if that file doesn't exist.
Thank you, now its clear. One more thing... I want to have a condition statement that if fourth oct of IP is 254 then just make it 0 and increment third oct. So xxx.xxx.3.254 => next xxx.xxx.4.0
I just added condition to awk but it doesnt seem to work...
Last edited by Manu1234567; 10-05-2013 at 07:25 PM..
I've the following data set. I would like to look at the column 3 and only use the rows which has the max value for column 3
Can we use the awk or sed to achieve it.
10 2 10 100
11 2 20 100
12 2 30 100
13 2 30 100
14 ... (7 Replies)
without using conventional file searching commands like find etc, is it possible to locate a file if i just know that the file that i'm searching for contains a particular text like "Hello world" or something? (5 Replies)
Hi All,
I have this userid:
# cat /etc/shadow | grep mysql
mysql:$1$O12345678901234/.:123456:0::14:::
Max password expiration is blank. What does it mean?
If it's like this below
mysql:$1$O12345678901234/.:123456:0:99999:14:::
then there's no expiration.
Thanks in advance for... (1 Reply)
From reading my C book, Im aware that the integers have a maximum value which depends on what type of processor you are using (since they use 16-bit or 32-bit instructions).
Now I know pointers are very flexible, since they can reference anything, but in the case of integer pointers, can they... (4 Replies)
1> Can anyone tell me what is the maximum no of parameters that can be passed to a file
2> i have 100 files amongst which in 500 files i have a string which needs to be searched how would get the names of those files. (1 Reply)
Hi All,
I want to choose the maximum value from a column values.
eg -
234
23
567
43
2456
5
678
8978
from thses values how to choose the max value ?
thanks.
roger. (3 Replies)
I have a file like:
<word> 5
<word> 3
<word> 5
<word> 2
<word> 6
<word> 8
<word> 12
and i need to know the max value of the second column, in this case 12.
Plz help me!
Actually i need the TOTAL, AVERANGE and MAX VALUE and i'm using this in... (10 Replies)
My code below is supposed to find which company had the most business and then print the appropriate fields from another file which are the companies ID number and name. I can loop through awk and display all the total amount of business for each company but I need help in only printing out the... (1 Reply)
My HP-UX 11.0 system is supporting an Oracle database. I have found a number of references on the Net to the "Max I/O size" in relation to setting Oracle parameters.
How can I tell what my max i/o size is? I originally made the assumption that it was referring to my stripe size but now I think... (1 Reply)