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

learn more… | top users | synonyms

0
votes
2answers
50 views

File sort by time issue

I have a requirement to identify sequence gap in a set of files. Sequence starts at FILENAME_0001 and ends at FILENAME_9999. After this the sequence is restarted from 0001. To implement a proper ...
3
votes
2answers
157 views

Is there a way I can grep recursively over all the files in the current directory to find a pattern and then print it in order of high to low?

So so far, the code looks like this: grep -rc 'Author' $1 It prints out all the files in the directory, which is taken as an argument. However, how would I sort the output (for example): - data1:...
1
vote
1answer
39 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 =========== -=-=-=-=-=- -------- ----------- ...
5
votes
5answers
2k 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
80 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
44 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 ...
8
votes
3answers
1k 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 ...
10
votes
1answer
235 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
29 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 RNU2-...
0
votes
1answer
35 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
66 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 ...
1
vote
1answer
82 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
35 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
17 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
77 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
22 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 ...
3
votes
2answers
25k 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 ...
0
votes
1answer
30 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
65 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
198 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
73 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
236 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
54 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 ...
0
votes
1answer
70 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
2answers
35 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
180 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 -F';'...
2
votes
2answers
85 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 ...
3
votes
2answers
298 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 TX001;C1321|VARCHAR|15|...
3
votes
1answer
185 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 ...
11
votes
6answers
4k views

Can I parallelize 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
5answers
18k views

Sort the output of find -exec ls

Is it possible to the output of find … -exec ls -ls ; sorted alpabetically, by filename? This is my cron command: find /home/setefgge/public_html -type f -ctime -1 -exec ls -ls {} \; This command ...
1
vote
0answers
69 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
406 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: XYZ38390....
1
vote
3answers
163 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. ...
1
vote
1answer
45 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 ...
-1
votes
2answers
59 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 ...
2
votes
1answer
62 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
106 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
70 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 ...
-1
votes
4answers
31 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 /local/dir/more/dir/...
3
votes
1answer
155 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 208.115.113....
2
votes
1answer
105 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 ...
3
votes
3answers
57 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 ...
2
votes
2answers
51 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 ...
5
votes
1answer
239 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
1answer
36 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 ...
2
votes
3answers
1k 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
4k 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
57 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
3answers
113 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 ...