Sort command -u removes non-unique item


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Sort command -u removes non-unique item
# 1  
Old 04-22-2014
Sort command -u removes non-unique item

I am wondering why the sort command removes the volume with 0 in it, but orders everything else. I have a list like this:

Code:
cat list1

/vol/list_vol0
/vol/list_vol1
/vol/list_vol2
/vol/list_vol3
/vol/list_vol4
/vol/list_vol5
/vol/list_vol6
/vol/list_vol7
/vol/list_vol8
/vol/list_vol9
/vol/list_vol10
/vol/list_vol11
/vol/list_vol12
/vol/list_vol13
/vol/list_vol14
/vol/list_vol15
/vol/list_vol16

Then the sort command does this:
Why is /vol/list_vol0 removed? Everything else is in proper order
The issue is related to the -u option, but I don't know why it would remove list_vol0 as the entry only appears once. When I remove the -u the sort looks ok. Don't need help on this as I can remove the -u, I just wonder why the -u option would do this.

Code:
cat list1 |sort -u -t_ -n -k2.4

/vol/list_vol1
/vol/list_vol2
/vol/list_vol3
/vol/list_vol4
/vol/list_vol5
/vol/list_vol6
/vol/list_vol7
/vol/list_vol8
/vol/list_vol9
/vol/list_vol10
/vol/list_vol11
/vol/list_vol12
/vol/list_vol13
/vol/list_vol14
/vol/list_vol15
/vol/list_vol16

# 2  
Old 04-23-2014
Whats the content of the first line in your file "list1"
If that is blank, then sort is conserding null and 0 as same and excluding the field with "0"
These 2 Users Gave Thanks to SriniShoo For This Post:
# 3  
Old 04-23-2014
To illustrate SriniShoo's point:
Code:
$ printf '%s\n' '' 0 000 0000 0.0000 +0 | sort -n

0
+0
000
0000
0.0000
$ printf '%s\n' '' 0 000 0000 0.0000 +0 | sort -nu

$

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

Sort unique

Hi, I have an input file that I have sorted in a previous stage by $1 and $4. I now need something that will take the first record from each group of data based on the key being $1 Input file 1000AAA|"ZZZ"|"Date"|"1"|"Y"|"ABC"|""|AA 1000AAA|"ZZZ"|"Date"|"2"|"Y"|"ABC"|""|AA... (2 Replies)
Discussion started by: Ads89
2 Replies

2. UNIX for Dummies Questions & Answers

Print unique lines without sort or unique

I would like to print unique lines without sort or unique. Unfortunately the server I am working on does not have sort or unique. I have not been able to contact the administrator of the server to ask him to add it for several weeks. (7 Replies)
Discussion started by: cokedude
7 Replies

3. Shell Programming and Scripting

sort split merge -u unique

Hi, this is about sorting a very large file (like 10 gb) to keep lines with unique entries across SOME of the columns. The line originally looked like this: sort -u -k2,2 -k3,3n -k4,4n -k5,5n -k6,6n file_unsorted > file_sorted please note the -u flag. The problem is that this single... (4 Replies)
Discussion started by: jbr950
4 Replies

4. Shell Programming and Scripting

sed command removes lines in file

Hi, I am modifying a file with sed command. i want to make SCORE= blank in the file whereever SCORE=somevalue. What will *$ do in the below command? cat $file | sed 's/SCORE=.*$/SCORE=\r/g' > newfile The last line is also missing in the new file. How to make SCORE='100' to SCORE=... (5 Replies)
Discussion started by: ashok.k
5 Replies

5. Shell Programming and Scripting

Unique sort with three fields

I have another file with three columns A,B,C as below 123,1,502 123,2,506 123,3,702 234,4,101 235,5,104 456,6,104 456,7,100 i want to sort such that i get a unique value in column A, and for those with multiple value in A, i want the lowest value in C. output should be Code:... (3 Replies)
Discussion started by: dealerso
3 Replies

6. Shell Programming and Scripting

Unique sort with two fields

I have a file with contents below 123,502 123,506 123,702 234,101 235,104 456,104 456,100 i want to sort such that i get a unique value in column A, and for those with multiple value in A, i want the lowest value in B. output should be 123,502 234,101 235,104 456,100 (3 Replies)
Discussion started by: dealerso
3 Replies

7. Shell Programming and Scripting

Awk sort and unique

Input file --------- 12:name1:|host1|host1|host2|host1 13:name2:|host1|host1|host2|host3 14:name3: ...... Required output --------------- 12:name1:host1(2)|host1(1) 13:name2:host1(2)|host2(1)|host3(1) 14:name3: where (x) - Count how many times field appears in last column ... (3 Replies)
Discussion started by: greycells
3 Replies

8. Shell Programming and Scripting

What some ideas with sort and get unique data

Hi all, I am writing a script where i can parse through the directory and get common string in two directories i get. The command below SUN_PLATFORM=`$FIND $STREAM_PATH . -depth -name ShareableEntities | $AWK -F"/" '{if($10 ~ /sun5/) print $0}'` gives the following output:- ... (1 Reply)
Discussion started by: asirohi
1 Replies

9. Shell Programming and Scripting

Perl sort unique by one field only

Hi all, I've searched the forum and I can find some code to sort uniquely in perl but not by a single field. I have a file with data such as the following: 1,test,34 1,test2,65 2,test,35, 1,test3,34 2,test,34 What i want to do is sort it uniqely by the first field only so I'd end... (2 Replies)
Discussion started by: Donkey25
2 Replies

10. Shell Programming and Scripting

Sort and Unique in Perl

Hi, May I know, if a pipe separated File is large, what is the best method to calculate the unique row count of 3rd column and get a list of unique value of the 3rdcolum? Thanks in advance! (20 Replies)
Discussion started by: deepakwins
20 Replies
Login or Register to Ask a Question