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

learn more… | top users | synonyms

0
votes
1answer
33 views

Using `tree`, how do I output files before subdirectories?

I tried to combine --dirsfirst and -r, but directories still show up on top, only in reverse alphabetical order. It seems like -r is applied first, which is also indicated by the man pages. Any other ...
1
vote
3answers
959 views

How to tar files with a sorted order?

If you tar a directory recursively, it just uses the order from the os's readdir. But in some cases its nice to tar the files sorted. Whats a good way to tar a directory sorted alphabetically? ...
7
votes
1answer
3k 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 ...
0
votes
0answers
41 views

How to find 100 GB of most recently modified files and send to rsync for local synchronization

I need to select 100gig of most recently changed files from a local directory and do an rsync to a local directory (skipping files that are already rsynced). If I try something like find . -mtime ...
19
votes
4answers
6k 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
3answers
37 views

How to list all files *.html bigger than {size} excluding some {*parts*}

I need a command to list files. But I have three problems: I want files ending with .HTML and .HTM If any file has parts like: google docs or form in the name, I want to exclude it. I want just ...
0
votes
0answers
60 views

Join, file is not sorted

I have two files whose first lines are File1 Locus_1174 [six columns of numbers] locus_6396 [six columns of numbers] Locus_12135 [six columns of numbers] locus_13689 [six columns of ...
31
votes
9answers
17k views

sort but keep header line 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 ...
1
vote
2answers
57 views

Reordering a file, based on a second file

I have a file that is out of order.I would like to reorder it by using a second file. File 1 1 ...
2
votes
2answers
316 views

How does the utility “sort” work? (why does it not work the way I think it should?) [duplicate]

I have 2 text files: $ cat /tmp/test1 "AAP" bar "AEM" bar "AA" bar "AEO" bar "A" bar $ cat /tmp/test2 "AEM" foo "AAP" foo "A" foo "AEO" foo "AA" foo I want to sort them $ sort /tmp/test1 "AA" bar ...
4
votes
3answers
1k 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 ...
1
vote
1answer
41 views

Why does this command not sort based on the uniq count?

I have lines in a log similar to: 2015/11/02-07:55:39.735 INFO failed with ERR_AUTHORIZATION_REQUIRED. (10.10.10.11:61618) is not a trusted source. 2015/11/02-07:55:40.515 INFO failed with ...
3
votes
1answer
40 views

How to list files named like XXXmmyy.dat in natural chronological order?

I use a Mac OS X (V10.9.5) and work in the X11 window, and I often need to deal with thousands of files named like XXXmmyy.dat, where XXX is a 3-letter acronym of a place, mm is the 2-digit month, and ...
78
votes
13answers
51k 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 ...
0
votes
1answer
52 views

How do I sort a file and output the latest record in case duplicates exist?

I save all the requests, received via API, in a file. I wish to process only the latest request if duplicate requests arrive. Sort command is not helping, I am using : sort -r -k 1.69,1.88 ...
3
votes
1answer
72 views

Strange default sort behaviour

I have some trouble to understand what is happening here: [guido@localhost 9]$ ls -1 Star\ Wars\ Episode\ * Star Wars Episode II Attack of the Clones.avi Star Wars Episode III Revenge of the Sith.avi ...
2
votes
1answer
67 views

“Count how many different starting letters are in languages names”

So I have this text document with 89 lines. In this document the first column of every line is another language. My task is to count how many different starting letters are used in the document. I ...
1
vote
2answers
31 views

Position of r before and after k in Sort

I have tried the following two scripts to sort a CSV file $ sort -t"," -k1,1 -k3,3 -k4,4 -k6,6r myFile.csv and $ sort -t"," -k1,1 -k3,3 -k4,4 -rk6,6 myFile.csv I found having the -r before ...
2
votes
2answers
904 views

Calculate median value for a column and say if this value is “OK” or “ERROR” if falls within acceptable range

I would like to calculate the median value of a particular column in a .txt file, output that value and also say if that output value is ok. I can do the initial steps and output the median value, ...
7
votes
2answers
17k views

Sort and count number of occurrence of lines

I have Apache logfile, access.log, how to count number of line occurrence in that file? for example the result of cut -f 7 -d ' ' | cut -d '?' -f 1 | tr '[:upper:]' '[:lower:]' is a.php b.php a.php ...
2
votes
1answer
165 views

Installed coreutils on CentOS for sort --human-readable flag but it still doesn't work

I'm trying to do du -h | sort -h, but my CentOS 5.7 doesn't have -h flag for sort. So I installed coreutils Updated: coreutils.x86_64 0:5.97-34.el5_8.1 Complete! yet sort still doesn't have ...
50
votes
5answers
43k 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 ...
1
vote
3answers
115 views
2
votes
1answer
126 views

sort based on column

10 awhdk; 14 hjoeow; 2 kdkld; 4 jkjdksl How to sort this based on column one (i.e the count) ? I'd want to get this output : 14 hjoeow;10 awhdk;4 jkjdksl;2 kdkld I need both the columns to be ...
21
votes
3answers
60k 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?
0
votes
3answers
55 views

Understanding options to sort

part 1 ps -e | sort -k 1 -nr What is the interpretation of the above command? I want to understand the role of -nr. It is not clearly given the man pages of sort. part 2 When you open the man ...
0
votes
1answer
34 views

Keeping first instance of duplicates when column values are interchangeable

I have previously asked a question about keeping the first instance of duplicates and the solution provided has been working perfectly until now (see Keeping first instance of duplicates). However, I ...
6
votes
5answers
17k 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 ...
2
votes
4answers
2k views

sorting filenames numerically when they have non-numeric prefix

I have files in the following format: x1 x2 ... x10 x11 ... x101 ... I want to rename these files, so they all have the same name length: x001 x002 ... x010 ... I can do this with files, that don't ...
0
votes
0answers
29 views

grep names from big list and sort it according to pattern [duplicate]

I have 2 big files as shown below. I want to read the pattern file and grep the line from full-info file and sort the channel name order according to pattern. pattern file HBO COMEDY; DTV CABLE ...
4
votes
1answer
3k 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 ...
6
votes
5answers
1k 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, ...
0
votes
1answer
40 views

How to find maximum number of different strings?

I have a file: 2.0-00-04 2.0-00-03 2.0-00-02 2.0-00-01 2.0-00-00 1.0-00-02 1.0-00-01 1.0-00-00 How can I find maximum number of each group? In the string above, output should be: 2.0-00-04 ...
0
votes
0answers
19 views

Properly sorting a csv file [duplicate]

The sort function looked promising, but as far as I know, it can't handle escaped line feeds, and the field deliminator option -t doesn't have an option that will take into account escaped commas. ...
2
votes
1answer
77 views

Wrong order with sort command

How to get sort command working with data separated by "|" (pipe character) ? Consider this sample file called "x" which have two fields: axis-AXIS|OK axis-AXISR|OK axis-AXISD2X|OK axis-AXISA|OK ...
4
votes
1answer
93 views

Non-standard sorting of the ls output

I usually include a date in the filename so that files and directories are listed in chronological order when I use the ls command, e.g. 2015-08-29_letter_to_santa.txt. A drawback is that ...
0
votes
0answers
25 views

Sorting different groups (separated by a line) based on 16th column

I have a CSV file which is in this format cluster 0 aaa bbb ccc ....... xxx yyy zzz bhc adf ghy ....... hjn dft cbn cluster 1 adg bhg klo ....... jio jik mkl asf ghb nbv ....... cvb xcz hga ... ...
13
votes
2answers
316 views

Fastest way to delete duplicates in large wordlist?

I need to deduplicate a large wordlist. I tried several commands and did some research here and here where they explain that the fastest way to deduplicate a wordlist seems to be using awk. awk ...
1
vote
3answers
159 views

Select and sort IP address keeping the whole line

So I need to sort the IP Addresses and then sort my line by them. I can sort IP addres in a file by using : sort -n -t . -k1,1 -k2,2 -k 3,3 -k4,4 If my file looks like : add method1 a.b.c.d ...
5
votes
2answers
841 views

Fastest `uniq` tool in linux

I have large text file (1.5 G), I want to know what the fastest and more reliable tool in linux is. I usualy use: awk '!x[$0]++' file.txt But when I use htop command I see my memory usage is ...
12
votes
4answers
566 views

Sort lines by number of words per line

Given input: hello: world foo bar baz bar: baz: bin boop bop fiz bang beep bap: bim bam bop boatkeeper: poughkeepsie I would like to sort it into most words at the top, to least at the end, like ...
7
votes
2answers
151 views

Sort command inconsistent behavior

I want to sort two files but I cannot get consistent results. It seems there are problems with collation but I cannot understand the reason. In sample files separator is a single space: file1: a b B ...
1
vote
1answer
54 views

“sort -h” not working in Redhat 5.9. Any way to upgrade it?

I'm trying to sort the folders disk usage in human readable format in RHEL 5.9. I mounted the drive as NFS in Cent OS 6.4, where sort -h option works fine. But in RHEL 5.9, it throws error as ...
6
votes
3answers
352 views

Print random lines respecting the order of the source file

I have a large text file (~500K lines) with short sentences (couple of words long). Additionally, there is some XML markup in most of the lines. Finally, the text file has been sorted before the ...
4
votes
4answers
619 views

Sorting directories by last modified date/time of the same-named contained file

Is it possible, using grep, find, etc, to sort a list of directories by the last modified date of the same-named file (e.g., file.php) within? For example: domain1/file.php (last modified 20-Jan-2014 ...
27
votes
5answers
32k 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 | ...
8
votes
7answers
3k 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 ...
2
votes
2answers
68 views

How can I list files by class/indicator (as in ls --classify) then by name?

ls --clasify append indicator (one of */=>@|) to entries. I would like to group the entries of the same class/indicator together. I can only find ls --group-directories-first for grouping the / ...
2
votes
5answers
231 views

How to sort file by character occurrences per line?

I'm quite new to Linux, and I've found quite a bit of useful information on how to do character counts in a file, but is there a way in Linux/terminal to sort a text file by the number of times a ...
8
votes
5answers
622 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 ...