linux sort command produces strange output


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers linux sort command produces strange output
# 1  
Old 08-11-2011
linux sort command produces strange output

cat a
.a
ba
.b
bb
.c
bc

sort a
.a
.b
ba
bb
bc
.c

NOTE: .a and .b appears before ba and bb, where as .c appears after bc.

In general

if the file has strings of the type .<x> and <y><x>,

then for all x <= y, .x appear before yx and
for all x>y, .x appear after yx

Is this a bug or an expected behavior? It latter is the case, then what is the explanation?
# 2  
Old 08-11-2011
What distribution you are using ?

In solaris, i get the below output

Code:
 
$ sort test
.a
.b
.c
ba
bb
bc
bash-3.00$ cat test 
.a
ba
.b
bb
.c
bc

# 3  
Old 08-11-2011
There are some environemntvariables that influence sorting, LANG and LC_ALL beeing the ones that are used most often.
Code:
$ cat mytext.txt
.a
ba
.b
bb
.c
bc
$ unset LC_ALL
$ sort mytext.txt
.a
.b
ba
bb
bc
.c
$ export LC_ALL=C
$ sort mytext.txt
.a
.b
.c
ba
bb
bc

# 4  
Old 08-11-2011
... with LC_COLLATE being the most specific.

Regards,
Alister
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk runs and produces output but with error

When I run the awk below, I get an error message awk -v OFS='\t' '$(NF-1)=="Benign" || ($(NF-2) OFS $(NF-1))=="Likely Benign" {$(NF)=$(NF-2) OFS $(NF-1)} {print $0 }' input awk: cmd. line:1: (FILENAME=VUS FNR=8) fatal: attempt to access field -1 input Chr Start End Ref ... (6 Replies)
Discussion started by: cmccabe
6 Replies

2. Homework & Coursework Questions

linux sort command

This is the question being asked: (Sort your data file by last name first, then by the first name second - save as first_last.) I am not quite sure of the type of sort I am being asked to perform. I have read the man pages of the sort command a few times, as well as searching online for possible... (10 Replies)
Discussion started by: demet8
10 Replies

3. Shell Programming and Scripting

Need a shell script to compare two directories and produces the output

Hi, I am using solaris OS 10 and Bash shell.I need a script which will compare the two directories and produces the output. Step 1: In detail say suppoose I have machine one and have a directory dir1. Script should iterate through the directories and subdirectories inside and produce the output... (10 Replies)
Discussion started by: muraliinfy04
10 Replies

4. Solaris

Getting strange output of who -r command

Hi At OK> prompt, I have run the boot -s command After system is coming on to multiuser state, when I run the " who -r" command, I get the following message # who -r run-level Oct 17 03:48 last= Means I dont see "S" after run-level keyword. Could any one... (2 Replies)
Discussion started by: amity
2 Replies

5. UNIX for Dummies Questions & Answers

gzip produces different output from the same input

Hi there, I'm puzzled. Compressing the same file (same name, same md5sum) at two different times will produce a different output. I mean the md5sum of the resulting .gz files are different. Does it make any sens to any of you? I'd like some explanations if you know what's going on. Thanks... (4 Replies)
Discussion started by: chebarbudo
4 Replies

6. Shell Programming and Scripting

Sort command giving wrong output

Hi all, I have a problem with sort command. i have a file which looks like this: "file1 1073 java/4 1073 java/180 1073 java/170 1073 java/176 1073 java/167 1073 java/40 1073 java/33 1073 java/136 28988 java/76 28988 java/73 28988 java/48 28988 java/26" and i want to sort... (8 Replies)
Discussion started by: usha rao
8 Replies

7. UNIX for Dummies Questions & Answers

Linux Sort command

Hello! Can anybody explain in laymen terms what the (+) option in the sort command for Linux does? Please. Thanks in advance!!:D (1 Reply)
Discussion started by: itisijayare
1 Replies

8. UNIX for Advanced & Expert Users

Sort command - strange behaviour

Hi guys, I have the following example data: A;00:00:19 B;00:01:02 C;00:00:13 D;00:00:16 E;00:02:27 F;00:00:12 G;00:00:21 H;00:00:19 I;00:00:13 J;00:13:22 I run the following sort against it, yet the output is as follows: sort -t";" +1 -nr example_data.dat A;00:00:19 (16 Replies)
Discussion started by: miwinter
16 Replies

9. Linux

vgscan produces no output using file descriptors on Oracle Enterprise Linux.

I wrote a simple program which will create a child process to execute a command and the output will be redirected to the file. Please have a look at the following code -> #include <stdio.h> #include <stdlib.h> #include <sys/stat.h> #include <fcntl.h> void execute(char **argv) { ... (0 Replies)
Discussion started by: sandiworld
0 Replies

10. UNIX for Dummies Questions & Answers

a strange message when executing the sort command

Dear all, when I issue the command: gunzip -c file.gz |sort the command is executed normally and correctly but a message keeps appearing everytime I run the command: the message: sort: missing NEWLINE added at end of input file STDIN Does anyone know what is the meaning of this message?... (3 Replies)
Discussion started by: marwan
3 Replies
Login or Register to Ask a Question