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

learn more… | top users | synonyms

4
votes
5answers
92 views

How do I sort on the first column every 4 lines in a file with a key in the second column

Example File : first column can have fixed set of 4 unordered values world1.com,world2.com,world3.com or world4.com second column is a key belongs to each line such that each of the four sets has ...
5
votes
7answers
9k views

Sort the files in the directory recursively based on last modified date

Sort the files in the directory recursively based on last modified date I have modified a lot of files in my directory want to know what are those files by sorting them by the last modified date ...
18
votes
3answers
1k views

Scalability of 'sort -u' for gigantic files

What is reasonable scalability limit of 'sort -u' ? (in dimensions of "line length", "amount of lines", "total file size"?) What is Unix alternative for files exceeding this in dimension of "amount ...
1
vote
1answer
29 views

Using Perl for Even/Odd numbers

Currently, I'm using a process to create a very specific set of four files. The Process I'm using is shown in the attached Process Image, below: The first line is part of a solution, given to a ...
3
votes
3answers
61 views

Using grep/sort/find to extract unique values

I have a bunch of text files that are named in YYYYMMDD.Txt format (so today would be 20160420.Txt). Each file is basically a log that contains a timestamp and and a unique ID, each value is ...
39
votes
4answers
12k 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 ...
31
votes
2answers
43k 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 ...
3
votes
1answer
53 views

GNU sort --compress-program compressing only first temporary

I am sorting big files (>100Go), and to reduce time spent on disk writes, I am trying to use GNU sort's --compress-program parameter. (Related: How to sort big files?) However, it appears in certain ...
2
votes
1answer
52 views

POSIX Awk sort array

I would like to sort an array with POSIX Awk, however I have discovered that: asort() asorti() PROCINFO["sorted_in"] are all GNU extensions. Can this be done with without GNU Awk?
1
vote
0answers
19 views

gnu sort --stable option not working [duplicate]

I want to sort a text file with GNU sort, by the first field, with field separator ":": $ cat aa a:895502/ a:2013-05-24 # without --stable, last resort comparison $ cat aa | sort -t: -k1 a:2013-05-24 ...
3
votes
3answers
185 views

Join two files each with two columns, including non-matching lines

I'm trying to match and merge two sets of sorted data, one set per file. Each file contains two columns: the key field and the associated value. The resulting output should contain three columns: the ...
2
votes
3answers
92 views

How to sort files in Bash with ddmmyy timestamps in name

I have a series of files with names of the form "foo.date.bar" where "date" is a six digit field such as 310715. So for example foo.310715.bar foo.260815.bar foo.110815.bar foo.040815.bar I would ...
0
votes
1answer
59 views

removing duplicates with tail [closed]

How can I remove duplicate in tail output? I'm using tail -f file.txt | sort file.txt | uniq it stops tail after some sec
3
votes
2answers
32 views

Sort by last character of input, then by preceding number?

I have a file that looks like this: foo03a foo02b quux01a foo01a foo02a foo01b foo03b quux01b I'd like it ordered by the last character (so a and b appear together) and then by the preceding ...
0
votes
1answer
34 views

linux - setting order in which files are read or output with utilities (sorting)

I'm having issues with programs reading files in the wrong order, and also outputting in an undesirable order with utilities such as ls. I've tried some of the LC_COLLATE options, but none of them ...
4
votes
1answer
52 views

What is the sort order when using conditional operators?

I wrote a bash script that processes a list of filenames (using glob expansion, as in for f in *) and then outputs a subset of this list to a file. Subsequently I read the content of this file into an ...
0
votes
1answer
71 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 ...
3
votes
2answers
46 views

Sorting by two columns

I need help with this homework assignment: Write a shell script named sales1 using nawk and sort commands to do the following: 1. print the file in two sections, east and west, with lines alphabetized ...
3
votes
2answers
55 views

Sorting based on last occurrence of character

I want to sort the file based on the text before the first comma, but also want a second level sort based on the date YYYYMMMDD in the sample input: Sample Input: ...
0
votes
1answer
36 views

Monitoring Server Connections - Netstat formatting issue

I have had a few issues with a server recently. So i just wanted to leave a window showing the unique and IP's of connected devices. I have been using: watch -n 5 "netstat -tn 2>/dev/null | grep ...
3
votes
1answer
43 views

Sorting Directories and Files

I want to use find and sort the response. I assumed that a simple pipe find ... | sort would do it, but the sorting behaviour is weird. For simplicity a simple text file: asdf/2/22 asdf/2/01 ...
-1
votes
1answer
22 views

Sorting and outputting in another file

How can I sort a file then output it into another file I never created or do I have to create the file I want to put in. Might not make sense how I am typing it so... Let's say the file I have is ...
2
votes
5answers
41 views

How do I sort mixed text&numbers (eg hostnames)?

Given input with mixed text and numbers (w/o leading zeros), how can I get it sorted in the "natural" order? For example, given the following input (hostnames): whatever-1.example.org ...
1
vote
1answer
29 views

Calculate hits within a timespan from log file [closed]

I need to use UNIX utilities that implement out-of-core divide-and-conquer algorithms so to decrease the amount of virtual memory used (cap of 1 mb). I have a large data set that is an apache log ...
2
votes
2answers
78 views

Sorting ls output where files end in numbers [duplicate]

Here is the output of my normal ls command: f1 f10 f11 f12 f13 f14 f15 f16 f17 f18 f19 f2 f20 f3 f4 f5 f6 f7 f8 f9 So I have 20 files. I need them displayed as : f1 f2 f3 f4 ...
3
votes
2answers
45 views

How to pin certain files when using sort?

Normally I am more creative with Unix commands and pipes, but not today. So what I have is this: collage.jpg DCIM001.jpg DCIM002.jpg or this: 001.jpg 002.jpg boston-collage.jpg or sometimes ...
3
votes
1answer
30 views

Sort log data with bash

I have a log file containing such entries 192.168.1.1;query=/etc/security/limits.conf;date=02.03.16 192.168.1.1;query=/etc/security/limits.conf;date=01.06.15 ...
0
votes
1answer
42 views

aix: how to sort ps by stime?

On AIX, for the top 10 cpu processes, I use ps aux | head -1; ps aux | sort -rn +2 | head -10 for the top 10 mem processes ps aux | head -1; ps aux | sort -rn +3 | head -10 How can I sort the ...
1
vote
1answer
29 views

sorting on two vertical columns

I have a file that I want to sort from the nth column (which is numeric) - not the nth field. The file looks schematically like: 1 Here are four words 9 8 5 2 Here's two 7 2 6 ...
0
votes
0answers
27 views

sort on column (not field) [duplicate]

I have a file that I want to sort on the nth column (which is numeric) - not the nth field; i.e. the file looks schematically like: Here are four words 9 Here's two 7 One ...
20
votes
5answers
7k 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 ...
2
votes
3answers
953 views

Creating recursively sorted RAR archive

For various reasons I decided to use RAR archive to store some data, instead compressed tar. Happy with decision, except for one thing: I can't find a way to store files sorted. Order of files is ...
14
votes
3answers
24k 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 ...
1
vote
2answers
47 views

How to reverse sort the output from grep -rc

I want to be able to sort the output from the grep -rc command, I am currently using the command: grep -rc "Pattern" . | sort -t: -rk2,2n however the list is still sorted from low to high, ...
0
votes
2answers
40 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
152 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): - ...
1
vote
1answer
34 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
59 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
39 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
27 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
1answer
31 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
57 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
62 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
31 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
15 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
73 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
19 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 ...