I'm trying to sort a text file "test":
By "sort test", I get:
It seems weird:
Comparing Line 2 and Line 3, it must be that '-' is bigger than '1'; however, comparing Line 3 and Line 4, it seems that '5' is bigger than '-'.
And the result of comparing one line to a previous line using strcmp function is:
It seems that "S_N15" and "S_S12" are not in the correct position.
The result (according to strcmp) should be:
Last edited by vgersh99; 11-09-2011 at 07:27 PM..
Reason: code tags, please!
First of all you have underscores in your strings and not dashes.
By default 'sort' sort alphabetically based on your local.
The octal ASCII value of the underscore is 137
The octal ASCII value of the 1 is 061
And upper case letters start at 101
This is what I get based on your sample after sorting with not switches:
which looks correct based on the previous ASCII value explanation.
I'm in the US. What local are you at?
The kernel I'm using is:
Linux ccm18 2.6.32-31-generic #61-Ubuntu SMP Fri Apr 8 18:25:51 UTC 2011 x86_64 GNU/Linux
Can't figure out why the "sort" behaves differently from yours.
Quote:
Originally Posted by vgersh99
First of all you have underscores in your strings and not dashes.
By default 'sort' sort alphabetically based on your local.
The octal ASCII value of the underscore is 137
The octal ASCII value of the 1 is 061
And upper case letters start at 101
This is what I get based on your sample after sorting with not switches:
which looks correct based on the previous ASCII value explanation.
I'm in the US. What local are you at?
The kernel I'm using is:
Linux ccm18 2.6.32-31-generic #61-Ubuntu SMP Fri Apr 8 18:25:51 UTC 2011 x86_64 GNU/Linux
Can't figure out why the "sort" behaves differently from yours.
Most likely your locale isnt "C" so use the locale command to find out what it is set to...
Output of above command lists a bunch of LC_* variables and if LC_COLLATE isnt set to "C" then do so or just set LC_ALL to "C" which overrides all settings and sets all LC_* variables to "C"...
Now if you rerun the sort you will get the desired result...
Hi All,
I have 2 pipe delimited files viz., file_old and file_new. I'm trying to compare these 2 files, and extract all the different rows between them into a new_file.
comm -3 < sort file_old < sort file_new > new_file
I am getting the below error:
-ksh: sort: cannot open
But if I do... (7 Replies)
Hi there,
I'm running into a very weird situation. Let's forget about the purpose of my initial script please. I noticed the bug whatever I'm trying to do.
I'm on an old server running bash 3.1.17.
Say we have the following script :
foo:~# cat /tmp/test
#!/bin/bash
f1() {
local... (9 Replies)
This really puzzles me. The following code gives me the error 'expr: syntax error' when I try to do multi-line comment using here document
<<EOF
echo "Sum is: `expr $1 + $2`"
EOF
Even if I explicitly comment out the line containing the expr using "#", the error message would still exist... (3 Replies)
I've posted about this before, but only recently narrowed the problem down to a specific cause.
Ok, first of all, the behavior:
It occurs when autocompletion brings up its list (not when there is only a single option). Basically, if I were to type, say,
cd ~/<TAB>
I would get something... (2 Replies)
Hi,
I have line in input file as below:
3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL
My expected output for line in the file must be :
"1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL"
Can someone... (7 Replies)
I need to sort the following file by the rhdiskpower devices in the last column:
Total_MB Free_MB OS_MB Name Failgroup Library Label UDID Product Redund Path
1024 851 1024 OCRVOT1_0000 OCRVOT1_0000 System UNKNOWN ... (3 Replies)
I had a site that sold stock photography and some guys I know set up a shopping cart and gallery system for it. One thing they did was give me an admin page (mysite.net/admin) where I could upload new images and change prices and all that. For that admin page they set a password popup prompt.
I... (4 Replies)
Is it normal behavior for a shell script that terminates to terminate its parent shell when executed with the "." option?
For example, if I have the example script (we'll name it ex.sh):
#!/bin/sh
if
then
echo "Bye."
exit 2
fi
And I execute it like this:
>./ex.sh
It... (6 Replies)
Hello,
I have been attempting to automate the addition of SSL certificates to keychains on a MAC using the "security" command. I've noticed two things, 1 of which I don't understand.
1. If I use something like "security add-trusted-cert -d -k /System/Library/Keychains/SystemRootCertificates... (1 Reply)
Hi,
I came across a script a few months ago that allowed you to use the following script to include the current time into your prompt (useful from auditting purposes):
# Set Prompt
typeset -RZ2 _x1 _x2 _x3
let SECONDS=$(date '+3600*%H+60*%M+%S')... (5 Replies)