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

learn more… | top users | synonyms

6
votes
2answers
145 views

Sorting with Perl respecting Locale Settings

Following data needs to be sorted respecting the locale sort order: wird sin wär pêche war Über Uber péché peach There was nor problem by using sort $ sort < data peach pêche péché sin Uber ...
3
votes
2answers
924 views

How to sort big files?

I have a PC with Intel(R) Pentium(R) CPU G640 @ 2.80GHz and 8 GByte RAM. Installed Scientific Linux 6.5 on it with EXT3 filesystem. Q: What is the fastest way I can do a "sort -u list.txt -o ...
3
votes
3answers
179 views

sort lines according to day

I have a text file in following format, and I need to sort the lines according to date. Is there some simple way to do it (preferably in bash) ? 2013-May-30 2 2013-May-21 10 2013-Jun-27 8 ...
6
votes
1answer
80 views

biggest possible number for sort -n

How to determine the "biggest number" so that sort -n will always put it at the end? I'm thinking of something along Inf in some languages but I'm not sure if anything like this exists for sort. ...
11
votes
4answers
13k 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
2answers
976 views

Counting number of times each IP address appears in log file

I have a file in the format as follows: $ cat file.txt 27.33.65.2 27.33.65.2 58.161.137.7 121.50.198.5 184.173.187.1 184.173.187.1 184.173.187.1 What's the best way to parse the file file.txt into ...
0
votes
2answers
252 views

Sort a text file according to a character within a field

I have a file named : newfile which consist of the following data 1 AC BB CC 2 AB CC DD 3 CA BB CC 4 BE DD EE 5 BD AA AA I type the following command in bash to sort the data according to the ...
3
votes
4answers
297 views

How to sort a list of files by time, given only the filenames

Given a list of file names, how can I sort it by file modification time? The resulting output needs to look exactly like the input with the exception that the data has been sorted accordingly. Here ...
2
votes
3answers
582 views

How to show CPU time for processes via top without 'root' procs

Okay, So I've been attempting this for about three hours now without success. How do you search/display/use the top command (or ps command if it works...) to output a list of all procs, sorted by CPU ...
5
votes
2answers
79 views

Sort one column only, keeping remaining columns untouched

How to (numerically) sort a specific column in a text file, without affecting other columns (irrespective of whether they are sorted or unsorted)? On other threads I found -s argument, but it does ...
0
votes
1answer
85 views

Sort in Linux for column, keeping other values intact

NODE_154_length 847 2997 NODE_154_length 3283 4509 NODE_154_length 4672 5715 NODE_154_length 6977 7768 NODE_29_length 3790 4317 NODE_29_length 4356 4712 NODE_29_length 4356 4712 ...
2
votes
3answers
28 views

Move line from output to the front of output or custom reordering

I have a command find "$PWD" -name __openerp__.py|awk -F/ -vOFS=/ 'NF-=2'|sort -u and I want to take a certain line containing /web/addons and push it to the front of output then do the same with ...
1
vote
1answer
43 views

How to sort these lines?

I have this text: menu.overlap.x: -7 menu.overlap.y: 0 !! Menu settings menu.title.bg: Solid Flat menu.title.bg.color: #fce855 menu.title.bg.colorTo: #daa30b menu.title.bg.border.color: black ...
25
votes
2answers
762 views

Why is sort -o useful?

UNIX philosophy says: do one thing and do it well. Make programs that handle text, because that is a universal interface. The sort command, at least GNU sort, has an -o option to output to a file ...
1
vote
1answer
47 views

Memory-efficient utility to return N first sorted values

I would like to implement a very popular MapReduce example using only existing programs operating in a UNIX way. The problem is to find N most frequent values in an enormous amount of data. The ...
4
votes
1answer
143 views

How can I find the sort order for ls with my locale?

I was using ls -l on a directory, and was surprised that spaces and underscores were ignored for the sort order. For example, $ echo $LANG en_AU.UTF-8 $ ls -l total 0 -rw-r--r-- 1 sparhawk sparhawk 0 ...
4
votes
3answers
235 views

Sort all directories based on their size

I'd like to sort all the directories/files in a specific directory based on their size (using du -sh "name"). I need to apply this command to all directories in my location, then sort them based on ...
2
votes
2answers
283 views

Sort based on the third column

I'm facing a huge 4-columns file. I'd like to display the sorted file in stdout based on its 3rd column: cat myFile | sort -u -k3 Is that enough to perform the trick?
3
votes
3answers
215 views

Print unique of who command

I want to show the online users using the who command but I want to have a unique output and not show any duplicates. I piped the output into awk but I am not very familiar with that, is this the ...
0
votes
1answer
58 views

How to perform custom sort

I have the following line in a file : [[0, [0, '1']], [1, [0, '2']], [2, [0, '3']], [3, [0, '4']]] [[0, [1, '5']], [1, [1, '6']], [2, [1, '7']], [3, [1, '8']]] [[0, [2, '9']], [1, [2, '10']], [2, ...
1
vote
1answer
47 views

List the lines with the highest scores

I have the following problem concerning the sorting of a content of a file. I have a file called points.txt and it contains the following table of data: Jim:4 Tim:8 Lin:6 Tom:1 Esko:2 Jaska:5 Erkki:7 ...
2
votes
1answer
81 views

Sort doesn't use natural order

I have used uniq -c and sort extensively on other machines, and it always worked very well. Now, on my new Ubuntu (13.04) machine, I end up with a weird ordering: % cat queries.log | grep INSERT | ...
3
votes
2answers
100 views

Ignore blank keys in coreutils sort

How do you ignore or is there a way to change the sort order of empty keys when using sort -k? # cat afile a b 11 20 93 45 55 26 09 31 How can I sort the empty column b values at the bottom so it ...
1
vote
5answers
495 views

Need some sed magic: Moving marked lines to the beginning of a file

I find myself in dire need of some sed magic (I really need to sit myself down and learn this). I have a file with lots of lines. After reviewing it, I've marked some lines by adding a star (*) to ...
0
votes
3answers
106 views

selecting rows that have the same value [closed]

I have a problem in selecting rows that have the same value. My data is too huge to go row by row to do that. I want you guys to let me know scripts that can perform this. My data looks like as ...
5
votes
5answers
303 views

Sorting blocks of lines

I have a file that contains 4n lines. Here is an excerpt from it containing 8 lines 6115 8.88443 6116 6.61875 6118 16.5949 6117 19.4129 6116 6.619 6117 16.5979 6118 19.4111 6115 8.88433 What I ...
5
votes
5answers
10k 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 ...
10
votes
4answers
556 views

Shuffle file randomly with some additional constraints

I have a huge music playlist and, while some artists have many albums, others have just one song. I wanted to sort the playlist so the same artist won't play twice in a row, or his songs won't end up ...
1
vote
3answers
177 views

How to sort and join at the same time?

I have 2 files, one having 2 columns, another having 1 column. The second file is sorted using sort -u. Now the task is I need to join this column with the first column of the first file, which is not ...
2
votes
2answers
97 views

When do `sort -k 2,3b` and `sort -k 2,3` differ?

The POSIX description of the -b flag for the sort command is Ignore leading characters when determining the starting and ending positions of a restricted sort key. I can understand the use for ...
0
votes
1answer
79 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 ...
-1
votes
1answer
124 views

Select a range of files from directory structure /year/month/date.db

I have databases stored in the directory structure year/month/date.db an example would be db/2013/10/15.db I need to be able to select a range of these with a script ("dbSelect ...
1
vote
4answers
160 views

Why are sort options -c (check if sorted) and -o (write to output file) not compatiable

I am sorting a large number of files one after another. Using sort -o file file. The for loop halted midway and before restarting I want to use sort's -c option to speedup sorting. But it says that ...
0
votes
1answer
75 views

What option(s) would you use to sort a file named foo in place, that is replacing the original file with the sorted version? [duplicate]

I have this homework question. I looked at the man page for sort and I believe the answer is -o, --output=FILE Is that correct? It is a Fedora server. We're supposed to look on man pages, if there ...
6
votes
4answers
774 views

uniq a csv file ignoring a column, awk maybe?

Given this file (annotations are not part of file, but form part of explanation)... x,a,001,b,c,d,y x,a,002,b,c,e,yy x,bb,003,b,d,e,y x,c,004,b,d,e,y x,c,005,b,d,e,y # nb - dupe of row 4 ...
0
votes
1answer
59 views

Get the most recent backup files [duplicate]

I'm googling for this, but the terms are so generic I'm getting way too many false positives, so what the hey, I'll ask here. I'm sure there's a simple answer but I don't generally script in *nix. ...
4
votes
1answer
73 views

Help with the sort command (numeric)

I have this output I'd like to sort numerically by port (starting at the 35th column): tcp 0 0 192.168.0.210:110 0.0.0.0:* LISTEN 3385/dovecot tcp 0 0 ...
2
votes
2answers
1k views

Any tricks to speed up sort?

For example for bzip there is pbzip, a parallel version of bzip. Is there any such parallelization tools for sort to improve performance?
3
votes
1answer
416 views

How can I sort a list of file names by some substring of the name?

I have a number of files with names like: beginning_num1_734_num2_1.363e+12_num3_800.pdf beginning_num1_735_num2_7.453e+13_num3_800.pdf beginning_num1_1007_num2_9.453e+12_num3_1200.pdf I'd like to ...
4
votes
3answers
316 views

Grouped sorting of continuous paragraphs (separated by blank line)?

I think I'm pretty experienced now in sorting by columns; however, I haven't found anything so far how to sort continuous rows. Supposing we have a text file that looks like this: (very simplified, ...
5
votes
1answer
2k views

Sorting a file based on one column using Unix and Awk

I need to sort the input file according the 6th column, which is the score. Input File: Sc2/80 20 . A T 86 Pass N=2 F=5;U=4 Sc2/80 20 . A C 80 Pass N=2 F=5;U=4 Sc2/60 55 . G T 90 Pass N=2 F=5;U=4 ...
1
vote
2answers
5k views

How to sort results from ls command by modification date (directories first)?

I can fire ls -lrt to get files and folders sorted by modification date, but this does not separate directories from files. I want ls to show me first directories by modification date and then ...
1
vote
2answers
237 views

How batch mv files to folders created and named by modification date?

I am quite new to the terminal stuff and I just couldn't find any answer on the aforementioned subject. On my OS X, I have a folder with about 4000 pics that I'd like to move into folders that are ...
1
vote
2answers
448 views

Sort lines based on a variable-width number at a fixed position

I'm trying to sort a file using the Sort command but its not working: The file contains lines like: photo1 photo11 photo12 photo13 photo17 photo18 photo19 photo2 photo22 photo23 photo25 photo26 ...
2
votes
1answer
240 views

Incorrect sorting according en_US.UTF-8

I'm seeing a weird behavior of the sort command when I sort by en_US.UTF-8. I'm trying to sort this file (LC_COLLATE=en_US.UTF-8 sort testdata): 㐀 㐃㐄 ▼▽◢ ㎏㎜㎝ bqz ㄠㄨㄩ─┃┆ ...
1
vote
0answers
33 views

Characters not defined into iso14651_t1_pinyin are not sorted properly

when I try to sort characters not defined in iso14651_t1_pinyin, no sort happens, they are simply left in place. I would expect to see them sorted according to their codepoint. Is there a way I can ...
3
votes
1answer
518 views

Can I unzip and merge sorted text files in a single operation?

I have tens of thousands of gzipped text files, each of which has already been sorted internally. I've written a script to unzip them (creating a copy) and then using sort -m to merge them. It all ...
0
votes
1answer
3k views

How to sort by multiple columns? [duplicate]

I have a tab-separated file, and I want to sort it by its columns 9, 14, and 16. By this I mean that all rows that agree at column 9 should be sorted by column 14, and among these, those that also ...
8
votes
3answers
3k 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 ...
0
votes
1answer
160 views

How to sort date: YYYY.MM.DD. HH:MM?

INPUT: b|2013.06.03. 18:47| a|2013.06.03. 13:15| c|2013.06.03. 13:53| needed OUTPUT: a|2013.06.03. 13:15| c|2013.06.03. 13:53| b|2013.06.03. 18:47| How can I sort the dates correctly in ...