The suggestions mentioned below are all incorrect for reasons stated in post #3.
Quote:
Originally Posted by elixir_sinari
Incorrect numeric comparison. Numerically, 1.10 is less than 1.9, but as a version number, 1.10 is greater than 1.9. To perform the comparison numerically and correctly, you'd have to transform the version number in some way. Perhaps something like a*1000 + b, where a is the first component of the version string and b is the second. Obviously, though, b can never be greater than or equal to the constant multiplier, or there would be some ambiguity.
Quote:
Originally Posted by expert
try below
A lexicographical sort is inappropriate for a version string. Comparing as strings, 1.9 is greater than 1.10 since 9 follows 1 in the collation sequence of every locale of which I'm aware. Further, lexicographical sort results can vary with locale.
Why specify the field separator in awk -F " "? A single space is already the default value for FS. awk treats that specially. A single space ignores leading and trailing blank characters and splits on sequences of blanks (in the C/POSIX locale, spaces and tabs). If you intended to split on spaces only, you must use a regular expression bracket expression: awk -F '[ ]'.
grep $var is vulnerable to regular expression metacharacters in the first column of the data. This may or may not be a concern, depending on what the real data in that first column looks like. Regardless, fixed string matching, -F, is the correct approach. You do not want to treat the contents of that first column as a regular expression that can match strings that are not exactly identical to itself. You want to treat that column literally. Consider it a bonus that fixed string matching is also simpler and faster.
Quote:
Originally Posted by jayan_jay
That is performing a lexicographical sort. See the previous example's critique for why a lexicographical sort is inappropriate.
Why? sort -nr will look for a numeric string at the very beginning of the line. If it doesn't find one, it will behave as if it read a zero. Since the first field in the sample data is alphabetic, all lines will numerically compare as equal to zero and to each other, which then requires sort to break that tie by performing a lexicographical sort on the entire line. Long story short, -n may as well not have been specified; given the sample data (and any data set where the first non-blank sequence is not a valid numeric string), sort -nr and sort -r give identical results.
Regards,
Alister
Last edited by alister; 06-29-2012 at 08:54 AM..
These 3 Users Gave Thanks to alister For This Post:
Is it my imagination, or did you change +0 to "" in the highlighted expression? (I had looked at it earlier and thought it looked good, but was sidetracked and did not post.)
That string comparison is incorrect. The +0 variant, forcing numeric comparison of $4, should work correctly.
Is it my imagination, or did you change +0 to "" in the highlighted expression? (I had looked at it earlier and thought it looked good, but was sidetracked and did not post.)
Yes, I had used numeric comparison earlier but then happened to cook up some pretty unusual (and unrealistic) input data which made me change it to a string comparison...
The numeric comparisons should work in this case as you said...
Hi All,
How worried is everyone about the Dirty Cow Linux exploit? Has anybody experienced attacks yet?
From the research I've done it seems that the exploit is "reliable" (that is it works nearly every time on vulverable systems) which is not good news.
We all believe that Unix/Linux... (3 Replies)
Good morning!
I met a problem on a FS with AIX 5.3
It's not possible to mount the FS because of a dirty superblock.
I tried few things without success. I need your help to solve my problem guys. Do you have any idea please?
Thanks a lot
drp01,/home/root # mount /GSPRES/data
Replaying... (9 Replies)
I am creating a small bash file that will take one argument and compile it:
#!/bin/bash
OUT=${$1%.cpp} # C++ source files always end in .cpp
g++ -Wall $1 -o $OUT
chmod 777 $OUT The error message says 'bad substitution', namely where OUT is defined. How to fix this? (1 Reply)