The sort tag has no wiki summary.
24
votes
8answers
3k views
how do you sort du output by size?
How do you sort du -sh /dir/* by size? I read one site that said use | sort -n but that's obviously not right. Here's an example that is wrong.
[~]# du -sh /var/* | sort -n
0 /var/mail
1.2M ...
21
votes
1answer
189 views
Why is sort changing the order of lines with identical sort keys?
Here is the data:
D 2
B 2
A 2
When I run this command:
sort -k2,2 file
it outputs:
A 2
B 2
D 2
My question is that when I specify only the second column -k2,2,
why is it that it sorts by the ...
13
votes
5answers
3k views
sort but keep header line in the at the top?
I am getting output from a program that first produces one line that is a bunch of column headers, and then a bunch of lines of data. I want to cut various columns of this output and view it sorted ...
10
votes
3answers
407 views
What is the difference between “sort -u” and “sort | uniq”?
Everywhere I see someone needing to get a sorted, unique list, they always pipe to sort | uniq. I've never seen any examples where someone uses sort -u instead. Why not? What's the difference, and why ...
10
votes
5answers
2k views
case-insensitive search of duplicate file-names
I there a way to find all files in a directory with duplicate filenames, regardless of the casing (upper-case and/or lower-case)?
9
votes
2answers
1k views
Why does ls sorting ignore non-alphanumeric characters?
When sorting file names, ls ignores characters like -,_. I expected it to use those characters in sorting as well.
An example:
touch a1 a2 a-1 a-2 a_1 a_2 a.1 a.2 a,1 a,2
Now display these files ...
8
votes
3answers
714 views
How to sort the string which combined with string + numeric using bash script?
This is the data what I want to sort. But sort treats the numeric to string, the data it no sorted as I expected.
/home/files/profile1
/home/files/profile10
/home/files/profile11
...
8
votes
5answers
548 views
How intelligent are unix utilities?
Unix utilities like sort, find, grep, diff et al are very handy to perform quick tasks, sometimes without writing any code at all.
I wanted to know what algorithms do they internally use and how do ...
7
votes
5answers
2k views
List files sorted numerically
I have a bunch of files from log1 to log164.
I'm trying to LIST the directory (sorted) in a UNIX terminal but the sort functions are only providing the format like this:
home:logs Home$ ls -1 | sort
...
6
votes
2answers
1k views
sort inplace - like sed --in-place - exists?
Am I blind or is there no option like --in-place for sort?
In order to save results to the input file, sed uses -i (--in-place).
Redirecting the output of sort to the input file
sort < f > f
...
6
votes
3answers
323 views
sort at jobs chronologically
Possibly a simple solution I misplaced.
How can I get the output of atq sorted chronologically, so I can easily see who's due to run next? The man page for sort doesn't have anything built-in to ...
6
votes
3answers
7k views
How to list files sorted by modification date recursively (no stat command available!)
How can I get the list of all files under current directory along with their modification date and sorted by that date?
Now I know how to achieve that with find, stat and sort, but for some weird ...
6
votes
1answer
763 views
How can I remove duplicates in my .bash_history, preserving order?
I really enjoying using control+r to recursively search my command history. I've found a few good options I like to use with it:
# ignore duplicate commands, ignore commands starting with a space
...
6
votes
4answers
2k views
How do I make ls sort underscore characters first?
I like being able to name files and directories with an underscore prefix if it's something I want to keep separate from other files and directories at the same level. On Windows and Mac, for example, ...
6
votes
4answers
280 views
Fastest way to determine if two sorted lists contain unique elements
I have two sorted files A and B where the size of A is much greater than B, e.g. A is 100GB while B is 50MB. I want to quickly determine if there are any lines in B that are contained in A, stopping ...
5
votes
2answers
628 views
sort output by column
I'd like to take this command find -maxdepth 1 -type d | while read -r dir; do printf "%s:\t" "$dir"; find "$dir" | wc -l; done ( from here ). which has an output of basically
./kennel: 11062
...
5
votes
2answers
228 views
How would I sort these directory names numerically?
I'm aware that I can somehow sort this output numerically (so cpu1/ follows cpu0/) ... I could probably get something to work eventually by splitting up the string various ways with awk, but is there ...
5
votes
2answers
104 views
Sort fields inline
I'm trying to sort within a line of input over an unknown number of fields:
Input:
ab bc
bc ab
cd ef bc
bc cd ef
cd bc ab
ef ab bc cd gh
Output:
ab bc
ab bc
bc cd ef
bc cd ef
ab cb cd
ab bc cd ...
5
votes
1answer
105 views
Alphabetizing names in `ls` alias with .files not intermingled
I am currently using the following ls alias: alias ls='ls -alhGkpsq --color=auto'. This results in following directory listing.
[03:35] bryson@brys ~ :$ ls
total 48K
4.0K drwx------ 4 bryson 4.0K ...
5
votes
2answers
233 views
sort every field numerically, varying field counts
I'm trying to sort some data using sort. I noticed it was sorting by digit rather than number, so I added the -n flag. It then seemingly only numerically sorts on the first field though. Breaking it ...
5
votes
3answers
582 views
How to sort (by whatever key) BibTex entries in `.bib` file?
I work with LaTeX and do versioning with Git. For bibliography management I use Mendeley.
The problem is that each time Mendeley synchronizes it's .bib exports,
they are in different order, what ...
4
votes
2answers
112 views
sort part of a file
How can I sort the file by the second column from the terminal. The content of the file is:
Nome Note
------------
Mehdi 0
Sunday 20
Others 10
Shnou 5
Using sort -t' ' -nk2 is not ...
4
votes
3answers
1k views
Get lines with maximum values in the column using awk, uniq and sort
I have a file with next format
2011-12-01 user1 access1
2011-12-01 user1 access2
2011-12-01 user2 access2
2011-12-01 user4 access2
2011-12-02 user1 access1
2012-01-01 user3 access1
2012-01-01 user4 ...
4
votes
3answers
2k views
How to find files in subdirs and sort them by filename in a single command?
Result of a normal find using find . ! -path "./build*" -name "*.txt":
./tool/001-sub.txt
./tool/000-main.txt
./zo/001-int.txt
./zo/id/002-and.txt
./as/002-mod.txt
and when sorted with sort -n:
...
4
votes
4answers
4k views
join : “File 2 not in sorted order”
I've got two files _jeter3.txt and _jeter1.txt
I've checked they are both sorted on the 20th column using sort -c
sort -t ' ' -c -k20,20 _jeter3.txt
sort -t ' ' -c -k20,20 _jeter1.txt
#no ...
4
votes
3answers
409 views
For each subfolder, sort files by name and rename them to sequential padded numbers (regardless of extension)
I have the following directory structure:
.
├── event-a
│  ├── album-a
│  │  ├── a.jpg
│  │  └── x.png
│  └── album-b
│  ├── a.jpg
│  ├── x.png
│  └── y.gif
└── event-b
├── ...
4
votes
1answer
394 views
Is gnu coreutils sort broken?
Consider the following input to sort:
cat > foo <<EOM
D,,5014978
DD,,25
D,I,1972765530
D,Y,4223624
-,Y,71285059
YA,I,2
EOM
Now try running sort foo
The output is not sorted when trying ...
4
votes
1answer
687 views
How to find out common elements between two files?
For an example, I have 2 files having following info:
File #1:
12
13
14
15
File #2:
12 1
13 2
14 2
15 6
16 7
17 8
Output File:
1
2
2
6
In the output file, I want only the second column ...
4
votes
1answer
444 views
Linux sort second last column
I would like know how to sort the second last column ? It has the word "days=" in front of the number. I'm able to get the column with awk '{print $(NF-1)}', but sorting is wrong.
457000 ...
4
votes
1answer
242 views
Renaming files from bash in linux
There is a bunch of files of the following format hh-mm-ss.png where hh, mm, ss are hour, minute and second. How can I rename all these files in the directory in a sequential way from 1.png til n.png ...
4
votes
4answers
190 views
How to shift filename numbers without collisions?
Consider this list of files:
$ touch index-{1,2,3,4,5,6,7,8,9}.txt
If I want to shift them down so they start at zero, it's relatively easy:
$ rename --verbose 's/^index-([1-9])\.txt$/$1/; ...
4
votes
2answers
293 views
Sort behaves strangely on case sensitive sorting
Sort is sorting differently than I would expect. I have this file, call it text.txt:
a 1
A 1
a 11
(the space is always one \t)
I want to sort them alphabetically by the first column. ...
4
votes
1answer
393 views
How do get unix sort to sort in same order as Java (by unicode value)
I shell out sorting to the unix sort command in a Java program I've written. However I am having problems arising from Java's string comparison behaving differently than the comparisons done by sort.
...
4
votes
1answer
77 views
Why is uniq ignoring Unicode and lines with a single letter?
I'm trying to combine both the American and British dictionaries into one large dictionaries, and I'm trying to remove all the duplicates from the superset, but it seems that uniq is not outputting ...
4
votes
1answer
499 views
Is there a search utility which can binary split search a large sorted (sequential) text file?
Yes, I know it sounds odd. Sequential and Binary-splits don't mix.. That is unless the sequence is the byte offset within the file itself...
I've scrambled together a binary split search in bash ...
4
votes
2answers
125 views
Unix sort out of memory
I'm sorting a 25 GB file containing 200M lines on Fedora 18 using:
sort -S 10G -T /bigdisk bigfile
and I am getting process killed due to no memory. The process isn't maxing out my RAM before death ...
4
votes
1answer
166 views
comm: file is not in sorted order
I used comm to compare two sorted files.
Each line in these files are positive integer numbers.
But the results show
comm: file 1 is not in sorted order
comm: file 2 is not in sorted order
How ...
3
votes
2answers
141 views
How to use output of one command as input in another command
I made a copy of all the backups made on Wed of every week
The time stamp of each file is not sorted but the day is Wednesday of every file
Now, I need to sort each file based on time Stamp e.g if ...
3
votes
2answers
298 views
Using sort with alphanumeric filenames
I'm sorting the results of a find command which finds all of the files in the current directory:
find . -maxdepth 1 -type f -iname "*.flac" | sort
What I'm expecting is a list like this:
./Track ...
3
votes
2answers
124 views
Delete duplicate images. Need Software for computing average color of an image
I want to delete duplicates in a massive bunch of images. Well as I have dups of the same picture in a different resolution I will make the deletion myself. BUT I want to do this in linear time. So I ...
3
votes
4answers
2k views
Sorting the output of “find”?
I need to be able to alphabetically sort the output of find before piping it to a command. Entering | sort | between didn't work, so what could I do?
find folder1 folder2 -name "*.txt" -print0 | ...
3
votes
1answer
1k views
How to numerical sort by last column?
I have this input:
sdkxyosl 1
safkls 2
asdf--asdfasxy_asd 5
dkd8k jasd 29
sdi44sw 43
asasd afsdfs 10
rklyasd 4
I need this output:
sdi44sw 43
dkd8k jasd 29
asasd afsdfs 10
asdf--asdfasxy_asd 5
...
3
votes
2answers
461 views
Trying to sort on two fields, second then first
I am trying to sort on multiple columns. The results are not as expected.
Here's my data (people.txt):
Simon Strange 62
Pete Brown 37
Mark Brown 46
Stefan Heinz 52
Tony Bedford 50
John Strange 51
...
3
votes
4answers
219 views
Sort input file by the results of a regex
I'd like to sort a file based on the results of a regex expression. For example, if I have the following property declarations in Obj-C
@property (nonatomic, strong) id <AlbumArtDelegate, ...
3
votes
2answers
547 views
Where has my `uniq` or `sort -u` line gone, with some unicode characters
What is going on in the following code snippet? I'm not getting my expected output.
I'd think it was a bug, but it happens for 2 different programs (uniq and sort), so I suspect it is something ...
3
votes
3answers
77 views
Sort using custom pattern
Is there a way to output file's contents using custom patterns?
For instance, having a file myfile with following contents:
a
d
b
c
..how would one sort it using following pattern: print lines ...
3
votes
2answers
190 views
GNU utility: sort
I have an issue sorting a file based on the first two columns.
The layout of the file is:
1 998688068 PizzaFan Insurance 22.47
5 072821325 Plaisio Computers 26.35
4 998688068 PizzaFan Food 27.32
5 ...
3
votes
2answers
440 views
What's the default order of linux sort?
For a long period I think the default behavior of sort program is using ASCII. However, when I input the following lines into sort without any arguments:
#
@
I got:
@
#
But according to the ...
3
votes
1answer
134 views
Sort command not working as expected
I have got a dataset like this
tack2@domain.com,2009-11-27
overflow@domain2.com,2009-11-27
overflow@domain2.com,2009-11-27
When I am running command to delete all of the same entries of column2
...
3
votes
1answer
487 views
File size limit exceeded in bash [closed]
I have tried this shell script on a SUSE 10 server, kernel 2.6.16.60, ext3 filesystem.
The script has a line like this:
cat file | awk '{print $1" "$2" "$3}' | sort -n > result
The file's size ...

