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

learn more… | top users | synonyms

13
votes
2answers
13k views

How to sort big files?

I have a PC with Intel(R) Pentium(R) CPU G640 @ 2.80 GHz and 8 GB of RAM. I am running Scientific Linux 6.5 on it with EXT3 filesystem. On this setup, what is the fastest way I can do a sort -u on a ...
1
vote
1answer
32 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 file....
15
votes
3answers
11k views

How to sort the string which combined with string + numeric using bash script?

This is the data what I want to sort. But sort treats the numeric to string, the data it no sorted as I expected. /home/files/profile1 /home/files/profile10 /home/files/profile11 /home/files/...
2
votes
1answer
99 views

How to sort columns independently? [closed]

$ sort -t $'\t' -k 1rn,1 -k 2,2rn -k 3f,4 listaprezzi 2050 900 bananas 5 1905 700 grapes 17 250 4000 oranges 10 230 9200 ...
5
votes
2answers
99 views

What is a good way to sort two log files as they are created?

I have two scripts running, both of which output a log file. I'd like to make a third script that can sort these logs by time stamp and merge them into one file as they are created. What is a good ...
-4
votes
1answer
27 views

Explanations of {} and -exec in the find command; of the -nr and +4 options to sort

Can some on explain the below command find . -type f -size +50000k -exec ls -l {} \; | grep -v "data/dr" | sort -nr +4 1) why { } is used ? 2) what is the purpose of using +4 is used after -nr? 3) ...
3
votes
3answers
55 views

Sort all rows horizontally by reference to columns in a particular row

I need to sort horizontally, not vertically, and sort seems to be designed for vertical operation. E.g. I have three rows as follows: banana/orange/apple/mango potato/tomato/onion/garlic chair/table/...
2
votes
1answer
27 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 ...
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, ...
1
vote
3answers
802 views

sort command in unix with numeric sort

I have file1 : "$lvl=57" "$lvl=20" "$lvl=48" "$lvl=17" "$lvl=58" file2 i want : "$lvl=17" "$lvl=20" "$lvl=48" "$lvl=57" "$lvl=58" Basically numerically sort of file1
1
vote
4answers
41 views

How to extract first name in Alphabetical order from multiple files

Say I have File1: Aaron Vernon Troy Roy File2: Jason Derek Mariano Alex I want to display: File1: Aaron File2: Alex What would be a single line bash command that could do both? I was ...
2
votes
1answer
102 views

How to sort files separately without merging?

File1: Brazil New Zealand Argentina Uruguay File2: Chile Russia Latvia Switzerland I realize that the command sort -n File1 File2 will sort all the files merged together and display it ...
3
votes
4answers
144 views

Trying to sort two list of numbers and using uniq to get the intersection

I have a file A and B so I used to the following command... (sort -n A B) | uniq -d which should give me the numbers which occur in both files. 1 2 2 3 4 5 11 11 12 31 These are the numbers I ...
1
vote
1answer
41 views

Sort text by specific location on each line

What I want to achieve is sorting lines of text by a specific point in the text (the lines of text have no spaces or columns). I've worked out a solution to this, but I want to know if there is a more ...
0
votes
1answer
30 views

how to print the count of matched /unmatched patterns and print multiple patterns separated by line

how to print the count of matched /unmatched patterns and print multiple patterns separated by line. Input example (test.log): This 23 line has eight 8888 This 11 line has three 3333 need 12 to ...
1
vote
1answer
34 views

Nautilus: How are files sorted?

I am quite new to Debian 8.4. I am not sure if this is the right community on stackexchange to pose this question. Please tell me, if not. My question: I am using the Nautilus file manager. I view a ...
2
votes
0answers
54 views

Sort mount points by mount time

With no command line arguments mount displays all mounted file systems, e.g.: /dev/sdy8 on /bar type ext4 (rw,relatime,lazytime,data=ordered) /dev/sdx6 on /baz type ext4 (rw,relatime,lazytime,errors=...
4
votes
5answers
105 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
10k 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 ...
0
votes
1answer
40 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
105 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 ...
42
votes
4answers
13k 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 ...
32
votes
2answers
46k 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
68 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
66 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
215 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
105 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
69 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
35 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 number,...
0
votes
1answer
36 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
69 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
79 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
47 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
70 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: AX,NO,NO,\PathAX/subj/defn/...
0
votes
1answer
49 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
44 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 asdf/20/...
-1
votes
1answer
25 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
43 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 whatever-10....
2
votes
2answers
82 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
33 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 192.168.1.2;query=/etc/security/limits....
0
votes
1answer
87 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
34 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
31 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 ...
21
votes
5answers
8k 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
985 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 ...
21
votes
3answers
29k 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 c....
1
vote
2answers
65 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, ...