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

learn more… | top users | synonyms

1
vote
1answer
22 views

Why do different installations of sort sort punctuation differently?

I got a file with content like this: ----------- =========== -------- -=-=-=-=-=- When I sort in a linux os, it comes like this: $ sort 1.txt =========== -=-=-=-=-=- -------- ----------- ...
2
votes
2answers
26 views

How to sort data by the numbers in third column? [duplicate]

If I have a file consisting of data that looks as follows, how would I sort the data based on the numbers in the 3rd column ? The space between the first two columns are NOT tab delimited but some ...
0
votes
2answers
35 views

sort each column(field) in a file separately [duplicate]

I am aware that it is possible to sort primarily by one field and secondarily by another field. For example: $ echo -e "1 5\n1 4\n8 2\n1 9" | sort -k 1,1n -k 2,2n 1 4 1 5 1 9 8 2 $ However, am I ...
10
votes
1answer
226 views

How to sort a file based on a section of a field

I would like to sort a file : D104HN-D104HA 8.320 4.521 1.69e+05 -- D104HN-D104HB* 8.320 2.823 2.93e+05 -- A90HB#-A90HA 1.655 4.207 7.12e+05 -- ...
0
votes
1answer
22 views

sorting a file on column 1 [duplicate]

I have a file in this format which I want to sort RNU2-46P 0 RNU2-2P 9 RNU2-63P 5 RNU2-36P 6 RNU2-56P 8 RNU2-17P 0 I want to sort it on column 1 and get this output RNU2-2P 9 ...
0
votes
0answers
51 views

sort files twice

I have a series of 300+ files that I need to sort twice, once by the date and a second time within that date by part of the filename. The only standard in the names is that ends with *mmddyyyy<time ...
0
votes
1answer
23 views

Sort words from n rows

i need to print all the unique words and their occurences from first n rows in a give file. I have to sorted by their number of occurences and then alphabetically.(the only separator is " ") ex: for ...
0
votes
2answers
41 views

Sort words in file

i've got some problems i'm not capable to overcome. I need to count the first let's say N words in a txt file. Then , i have to print them in decresing order, followed by the number of occurences.The ...
0
votes
1answer
36 views

What is meant by -k1,1 in sort

I am following this script and trying to understand what happens at each line. In the following line extracted from here it involves sorting some fields. In the 14th example given here it says -k2,5 ...
1
vote
2answers
28 views

Unix sort function doesn't completely sort string with numbers

I have a file that contains two columns separated by tab. A10 A10_motorway_(Switzerland) A-10 A-10_N/AW A10 A10_Networks A-10 A-10_road A10 ...
0
votes
1answer
12 views

Manipulate du's output to get a custom printout [duplicate]

I typically run the command below to check size on each directory. du -sBM /* | sort -nr | head -n20 However, specifying a block size of "M" here will give everything a value in "M". The problem ...
2
votes
2answers
63 views

How to sort data stream by 2 column names (column number may vary)?

I get a stream of data from an API with which look like this: redID blueID whiteID 1 22 2 44 15 41 2 15 15 31 2 14 What I need to do, is to sort ...
1
vote
1answer
18 views

How can I find only the catalogs and sort them by size

How can I find only the catalogs and sort them by the size (human-readable). I tried with find -type d | xargs du -h | sort -rn But something goes wrong. And all the time its sorted by the ...
0
votes
1answer
28 views

sorting using the -k command

I have a script that gets people to enter name, number and date in the format of YYYY/MM/DD which then appends to a file so it looks like: Alex, 133454543, 1990/12/14 Tom, 234234235, 1992/10/09 I ...
1
vote
1answer
38 views

Find oldest directory name on a remote server?

I'm writing a backup script of sorts. My backup server contains 3 directories (named by date in the MM-DD-YYYY format) For example: 12-22-2015 12-28-2015 12-29-2015 Im writing my backup script ...
3
votes
1answer
80 views

Unexpected sort order in en_US.UTF-8 locale

While trying to answer this question about SQL sorting, I noticed a sort order I did not expect: $ export LC_ALL=en_US.UTF-8 $ echo "T-700A Grouped" > sort.txt $ echo "T-700 AGrouped" >> ...
4
votes
1answer
63 views

How to get this collation in sort?

I need to set up command sort, so it is sorting lines into this order: Akira Kurosawa Al Ernest Garcia Alain Sarde Alan Ladd, Jr. Albert S. Ruddy Alberto Grimaldi Alfred Hitchcock Amanda Plummer ...
8
votes
2answers
227 views

Why non-number record shows after “0” in sorting?

I want to sort files according to the number in the filename. Here are the files: $ ls *.f 0.f 13.f 1.f 22.f 4.f abc.f The sorting result: $ ls *.f | sort -t. -k1n 0.f abc.f # note this file! ...
0
votes
1answer
32 views

ls default sorting inconsistent

Why does adding identical characters to the end of filenames change the sort order as shown below? In any sane string comparison method I would expect the comparison of 2 strings to not differ if the ...
1
vote
2answers
33 views

Find out most frequent strings in section of file

I have a file that looks like this: o99 ksad<tab>abcde $%!H$!(<tab>00 !sdaf as<tab>12 sarwa &!§! &% (where <tab> represents a real TAB character). For clarification: It ...
4
votes
2answers
137 views

concatenate n lines with sed

Recently, I asked a question how to sort pairs of lines, and one of the answers suggested concatenating lines with sed, like this: cat file.txt | sed -n 'N;s/\n//;p' | sort -t";" -k43,43n | perl ...
4
votes
2answers
276 views

Unix Multiple Column Sort Issue

I am trying to sort a file: TX001;A0004|Number|5|0|Y|1 TX001;A0110|VARCHAR|5|0|Y|4 TX001;A1332|VARCHAR|15|0|Y|3 TX001;B3321|VARCHAR|15|0|Y|5 ...
3
votes
1answer
137 views

Sorting the output of ps does not work

I want to sort the output of the following command based on pcpu: ps -p 29492 -L -o pid,tid,psr,pcpu I tried the following: ps -p 29492 -L -o pid,tid,psr,pcpu --sort=pcpu But it doesn't seem to ...
1
vote
0answers
40 views

Removing duplicates in a large text list

I've searched around the internet and stackexchange for this. Even though there are lots of similar topics, I haven't found a solution yet. So, I have a quite large list (approx. 20GB), which ...
1
vote
4answers
164 views

How to sort files by part of the filename?

Given the files below: ABC38388.SC01.StatueGrade_MKP ABC38388.SC02.Statue_GKP DEF38389.SC03.Statue_HKP XYZ38390.SC00.Statue_WKP How can I list them all based on the SC value, like this: ...
3
votes
2answers
56 views

sort file but keep pairs of lines together

I have a file, with entries of the structure a1;b1;c1; d1;e1;f1;g1 a2;b2;c2; d2;e2;f2;g2 etc. I want to sort this file via the g's, but keep the abc's with the corresponding g. Is there any nice ...
1
vote
3answers
57 views

How to sort blocks of lines with a specific line from the block?

I have a file with the data like this BEGIN hello2 5 world1 END BEGIN hello4 2 world5 END BEGIN hello6 4 END I want to sort the lines in the following manner based on the number inside the block. ...
2
votes
1answer
41 views

sort ignores mode for second key

I am trying to sort a file that contains entries like this. This is the output of head file.txt | sort -n 1 1 360030.650313113 23.6496749206273 1 2 184005.303709890 ...
0
votes
2answers
34 views

Sorting multiple line columns

In the text: 35 EAST 23rd Street SOUTH AFRICA 5 600 5000000 6 83 NORTH YELLOWLIGHT AVENUE SOUTH AFRICA 4 700 7000000 5 777 NEW AVENUE SAUDIA ...
3
votes
1answer
56 views

sort behaves weirdly with scientific notation

I have a file with semicolon separated fields, which I want to sort according to general numeric value of the 26th column. I tried this: cat file.txt | grep -v setch | sort -t";" -k26 -g The grep ...
0
votes
1answer
39 views

sort and uniq commands not running as expected when run though cron

Below is a part of script which gives proper output when run manually but gives incorrect output when run using cron: sort < file1.out | uniq -ic |sort -nr> file2.out When run on the command ...
0
votes
1answer
38 views

how to get latest file in each dir

Is there a Unix command to get the latest file in logsarchive of each dir of /app/instance? In the example below, I have 5 folders in /app/instance: as_a, as_b, as_c, aunz, naeu and I need to get the ...
0
votes
1answer
46 views

bash: How to determine the largest number (newest version) from: ls *.tar.gz | cut -c 2-4

Hi I'm trying to get the largest number (newest version) of a file, I got a bunch of tar.gz files in a directory, versions of some software in the format v${version_number}_software.tar.gz, where ...
1
vote
0answers
19 views

sort behavior when using numerical option: “sort -k2,2 -nk6,6 foo” vs “sort -k2,2 -k6,6n foo”

The two examples in the title produce very different results. The first (sort -k2,2 -nk6,6 foo) brings back the following results: 153759 townhome 900 2 1 79000 876543 townhome 745 2 1 79000 222999 ...
3
votes
1answer
95 views

Unix - count unique IP addresses, sort them by most frequent and also sort them by IP when number of repetitions is same

I have a list of IP addresses in file: 72.204.55.250 72.204.55.250 72.204.55.250 72.204.55.250 72.204.55.250 96.41.51.202 208.115.113.91 178.137.94.166 178.137.94.166 ...
2
votes
1answer
56 views

How to sort text file by column starting at certain character position? [duplicate]

Considering the following input file (example)... afaefkl aaa al kmm ddd aajwoe bbb bnm aefp ccc ... what would be the most straight-forward way to sort it by column 2 (starting at ...
-1
votes
4answers
13 views

sort and du together to list file sizes but the output unit is wrong

So I have a large list of files to sort by sizes and this is what I got so far: du -ha /local | sort -n -r | head -n 10 1020K /local/dir/more/dir/filesnames.blabla 1020K ...
2
votes
2answers
48 views

Combine columns using awk? (Or other suggestions)

I'm trying to be a bit effective and need a script or command solution. Say I make a file with 2 columns, or two files with one column, whichever is easier: AA1 B2 ZZ1 YYY XX1 AA2 B2 ...
3
votes
3answers
55 views

Sorting more than one column

I have a file which has content that looks like this: 19.58 1925 Alpha 20.40 1924 Otter 13.66 1920 Gold I am trying to sort it "column by column" to output the following: 13.40 1920 Alpha 19.58 ...
-1
votes
1answer
43 views

sort log lines with stack stacktrace in middle

Consider the following entries in a log file: 2015-03-30 10:19:44,200 DEBUG [Default : 1] [Application:ABC BIW: IDA:6d87de8e-1276-4496-b49d-dd4cd375cbe4 Info:P23 Code:ABCD] A log message 1 2015-03-30 ...
5
votes
1answer
123 views

Sort output of awk except for first line?

This is a use case I am continually running into in parsing CSV files. When it is an inline awk script embedded in a shell script, I can use this workaround: myfile=$(mktemp) awk '(awk script here)' ...
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 ...
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 ...
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 ...
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 ...
1
vote
1answer
40 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 ...
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 ...