I have one file like this:
This can be easily sorted by the following command:
Since you didn't give sort a -t option, with the data you have above, the command:
is an inefficient equivalent of the command:
(There is no third field. And even if you used -t/, the start of the 3rd field is not numeric.)
Quote:
Originally Posted by newbie2010
But I have another file like this:
This file can't be sorted by file |sort -k5,5n or any other command.
The only way I've gotten it to sort is by the following:
I am wondering if there is a certain criteria that will cause you to need to use a character numerical sort instead of a column sort? I am sort of confused on this.
This is simple. If you have a string of digits that are not all the same length (same number of digits) and you want to sort them by numeric value (e.g., 5, 25, 100) instead of as a string by collating sequence (i.e., 100, 25, 5), then you need to sort that portion of your input file using a numeric sort instead of using the default alphanumeric sort.
Quote:
Originally Posted by newbie2010
In addition, I am also wondering if sort allows you to use the case insensitive option with numerical sorts. What if I had Scratch4 and scratch4 as paths? From what I can see, you can't use the numerical sort and the -f option even if you specify the column and character to use. It will always put the upper case at the top. Is there a way to turn this off through collation or LC_COLLATE?
You didn't have any data that would show whether or not a case insensitive sort would matter. "B" comes before "CRA" which comes before "crd" with both case sensitive and case insensitive sorts.
Here is a script that shows a couple of slightly more complex input files, the commands I used to sort them, and the sorted output that seems to match what you're trying to do:
The output produced (with my expanded test files) is:
Is this what you were trying to do? Please take another look at the sort man page to figure out why this works. If you still have questions about how the sort keys work in these two sort commands, let me know what doesn't make sense.
I usually ise find to search a file or name on the unix, since I am not administrator, there will be many line appear 'cannot access',usually a hundred of lines. How can I prevent this line coming out? only show I want?
The command I use is :
find / -name abcdef -print
Thank all expert. (1 Reply)
how can I find cpu usage memory usage swap usage and
I want to know CPU usage above X% and contiue Y times and memory usage above X % and contiue Y times
my final destination is monitor process
logical volume usage above X % and number of Logical voluage above
can I not to... (3 Replies)
Hi to all.
I'm trying to sort this with the Unix command sort.
user1:12345678:3.5:2.5:8:1:2:3
user2:12345679:4.5:3.5:8:1:3:2
user3:12345687:5.5:2.5:6:1:3:2
user4:12345670:5.5:2.5:5:3:2:1
user5:12345671:2.5:5.5:7:2:3:1
I need to get this:
user3:12345687:5.5:2.5:6:1:3:2... (7 Replies)
Hi all,
Can you please tell me the command, with which one can know the amount of space a specific directory has used.
df -k . ---> Displays, the amount of space allocated, and used for a directory.
du -k <dir name> - gives me the memory used of all the files inside <dir>
But i... (2 Replies)
I am trying to output a log file from cp usage. I think this can be achieved. In my code I have this.
cp -i -v ~/files/* ~/backups/oldfiles/;; > ~/logs/logfile.logThe error I get is "syntax error near unexpected token '>'
What am I missing? (7 Replies)
Hi,
Could you please let me know, why we should not use '.' in move command, if we use it, is it something wrong.. Please share the details on it.
/home/rahualux/emp.csv /home/rahualux/details/employee_files/.
Or other example for mutlipile files
/home/rahualux/*.csv... (3 Replies)