Sorting text files or other data, for example with the sort utility.

learn more… | top users | synonyms

37
votes
9answers
12k 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 ...
6
votes
2answers
4k 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 ...
12
votes
6answers
5k 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 ...
17
votes
5answers
6k 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 ...
4
votes
2answers
1k 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 ...
1
vote
3answers
460 views

Sort with unequal whitespace in first column

I need to sort this list by name, high temp and low temp: Kuala Lumpur 78 56 Seoul 85 66 Karachi 95 75 Tokyo 85 60 Lahore 85 75 Manila 90 85 I figured since whitespace is the delimiter for a column ...
10
votes
5answers
3k 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)?
3
votes
6answers
3k views

Get text-file word occurrence count of all words & print output sorted

I had a command which would work through a text file, count all the occurrences of the words and print it out like this: remy@box $˜ magic-command-i-forgot | with grep | and awk | sort ./textfile.txt ...
3
votes
1answer
2k 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 ...
9
votes
2answers
2k 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 ...
4
votes
1answer
613 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 ...
5
votes
2answers
130 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
2answers
413 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 ...
4
votes
2answers
533 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. ...
2
votes
2answers
115 views

Select greatest numbered filename

Simple requirement but can't find anything online which can achieve it. I have a list of dated files as below... filename_20120101.dat filename_20120102.dat filename_20120103.dat I ...
2
votes
2answers
1k views

Issues of using sort and comm

I was trying to find the intersection of two plain data files, and found from a previous post that it can be done through comm -12 <(sort test1.list) < (sort test2.list) It seems to me that ...
0
votes
1answer
57 views

Why this sort command gives me an empty file? [duplicate]

prova1 is a file with some text. When I run this code prova1 become empty: sort prova1 > prova1 I know that to achieve the effect I can do: sort prova1 -o prova1 I would just know the reason ...