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

learn more… | top users | synonyms

1
vote
4answers
96 views

Sed/awk/perl: reversing order of comma separated values, preserving other text

I have this text: LABEL1 .BYTE 01, 02, 03, 04, 05 .BYTE 01, 02, 03 I need to reverse only comma separated values order: LABEL1 .BYTE 05, 04, 03, 02, 01 .BYTE 03, 02, 01 I need ...
2
votes
2answers
42 views

Making sort use all CPU CORES

htop is showing that the "sort" command only uses 1 CPU CORE (on an RPM based Linux distro). How can I tell it to use all the available CPU CORES?
3
votes
2answers
218 views

How to concatenate two files in a new one and sort the output in one line

I have two files with some names in them, when I ran cat file1 file2 | sort, the terminal shows the names sorted alphabetically, but when I run cat file1 file2 > file3 | sort I don't see the sorted ...
2
votes
2answers
4k views

Sort data in descending order of first column, for equal values, use second column in ascending order

Allow me to clarify: Assume I have some keywords with frequency of their usage: 12 Hi 7 Hash 7 C++ 9 Superuser 17 Stackoverflow 9 LaTeX 42 Life 9 Ubuntu What I want, is to sort this data ...
1
vote
2answers
146 views

sort and ls — why aren't capitalized letters sorted first?

I want a sorting like this, with capitalized letters before lowercase: -rw-r--r--. 1 0 0 183 2014-10-14 20:17 ./CHECKSUMS.md5 -rw-r--r--. 1 0 0 185 2014-10-14 20:17 ./CHECKSUMS.asc ...
3
votes
4answers
2k views

How to reorder a large number of columns?

I'm looking for a pipeable one-liner to reorder a large number of columns (where manually entering the column numbers in e.g. an awk command such as awk '{print $3,$2,$1}' is not feasible). The order ...
0
votes
1answer
29 views

Sort three columns? [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 ...
-2
votes
0answers
14 views

how do I use sort to output to anoter file [closed]

I have created a file called stuff that has colors, drinks and animals in it. Each line is separated by a tab and there is a newline at the end of each line. e.g. red beer owl\n green ...
12
votes
2answers
503 views

How does awk '!a[$0]++' work?

This one-liner removes duplicate lines from text input without pre-sorting. For example: $ cat >f q w e w r $ awk '!a[$0]++' <f q w e r $ The original code I have found on the internets ...
4
votes
3answers
124 views

Finding files on a Unix server and sorting by size

I have a web server where I have run out of space and it's causing issues with the WordPress sites I am running on them. I know that I have a lot of large .png files (the fact that it's PNG is a ...
3
votes
2answers
46 views

Sorting strings with ANSI escape codes

I am trying to print a sorted list of all zsh options, with set options colored green and unset options colored red. I cannot get sort to work properly with on the colored lines though.The below ...
6
votes
7answers
2k 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
56 views

Should I use piping or redirection for input to 'sort'

I want to do awk -F "," '{print $1 }' inputfile1.txt | sort -u > distinctOutput.txt Is this good performance-wise ? Or should I redirect / use a temp file since I think it is better to make sort ...
0
votes
1answer
37 views

The sorted file is not saved correctly [closed]

If I sort a file, I want save it in the new one. I use for this just: sort -nk{fieldnumber} test.json > testsort.json In the output the columns are shuffled and the column, which I have sorted, ...
3
votes
1answer
144 views

Putting Files in Ascending order (not on time stamp basis) in Unix [closed]

How do I list files in Ascending manner, not on time stamp basis. EX:- Original listing A_2001 A_2002 A_2003 A_2004 B_2001 B_2002 B_2003 B_2004 Desired output:- A_2001 B_2001 A_2002 B_2002 ...
5
votes
3answers
2k views

What's the default order of Linux sort?

For a long period I thought the default behavior of the sort program was using ASCII order. However, when I input the following lines into sort without any arguments: # @ I got: @ # But ...
1
vote
1answer
20 views

Numeric sort by the column values

For example I have some test file and want to sort it by the column values. After awk -F'[:,]' '{print $16}' test.json I get next output for the column 16: 123 457 68 11 939 11 345 9 199 ...
3
votes
2answers
111 views

Sorting by a name field?

I am trying to sort the following file http://pastebin.com/EqA2SUMy. But the part I am trying to sort is the 11 field and only if the first field is atom. Here is an example ATOM 33 CG ASP ...
0
votes
0answers
49 views

Sorted HTML table

I need a very quick and easy way to sort HTML tables. The table rows contain images that should stay with their appropriate row. I tried pasting my HTML into Libre Office calc, but the images are not ...
0
votes
1answer
26 views

What's with `-` in filename affecting sorting order depending on platform? [duplicate]

I just checked if contents of directory on my cygwin/Win7 development system, and test embedded platform running Linux+Busybox are the same. Simple, cat * | md5sum on both (RXVT/Bash on Cygwin, serial ...
47
votes
10answers
19k 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 ...
5
votes
4answers
786 views

For each subfolder, sort files by name and rename them to sequential padded numbers (regardless of extension)

I have the following directory structure: . ├── event-a │   ├── album-a │   │   ├── a.jpg │   │   └── x.png │   └── album-b │   ├── a.jpg │   ├── x.png │   └── y.gif └── event-b ├── ...
2
votes
1answer
118 views

Sort the 'last' output by month

I know that the command last | tac is enough, but I want to do it using the sort command. I cannot sort it by column, it always sorts the first one only. Using bash on Arch Linux.
7
votes
3answers
285 views

How to sort vertically and horizontally?

Before (INPUT.txt): Foo#1 Foo#2 Foo#3 Foo#4 Foo#4 Foo#5 SUM Bar#1 0 0 0 0 3 0 3 Bar#2 2 0 1 0 0 0 3 Bar#3 0 0 0 2 2 0 4 Bar#4 0 0 1 ...
2
votes
3answers
2k views

How is it possible to sort ps command's CPU field?

I'm trying to make a small command that will find the processes that use the most CPU power. Firstly, I use ps aux > file.txt and then cut -c 16-20 file.txt | sort -n | tail -5. The result I get ...
3
votes
2answers
97 views

Identify lines that are out of order

I have a process that generates output mostly in lexicographically sorted order according to a (timestamp) field, but occasionally the lines will be output in the wrong order: 2014-08-14 ...
1
vote
2answers
59 views

How can I sort a .txt file by two columns?

Feb 7 domainserver dovecot[37495]: auth(default): od(tjones): lookup failed for user: tjones Above is a sample output of what I'd like to sort. I'd like to sort by date on the first column, but ...
6
votes
4answers
124 views

Find newest file. Multiple Filetype restrictions

I want to write a command that gives me the newest file in a directory recursively. But that's not my only limitation. The files has to be an mp3 or a jpg file. (case insensitive prefered) I only need ...
6
votes
2answers
95 views

What should be the buffer size for the sort command?

I have a machine with 2 TB of RAM and I am running a sort command on a file of size 150G where I have specified the buffer-size as 1000G, after doing my bit of reasearch on google, I got this piece of ...
4
votes
2answers
39 views

How to sort a collection of lines from different files?

I want to sort second line in each file by second column, and also print name of the corresponding file. I am doing it like this - rm tmp; for filename in file*; do num=`head -2 $filename | tail ...
0
votes
1answer
114 views

Sorting file by second column

How can I manipulate a two columns tab-separated text file by sorting by the first element of the second column (only if the first column element is the same)? Exemple: Input File 1 A 1-2 A ...
0
votes
1answer
69 views

Why am I not getting correct output with sort command [closed]

This is what I have tried so far sort /etc/passwd -t: -k1 > ~/passwd.bylogin I keep getting an error that the output is wrong. The question is: Sort the /etc/passwd file in alphabetically ...
3
votes
4answers
140 views

How to sort with a delimiter that is several characters long?

INPUT: $ cat a.txt 1FOO2FOO3 4FOO5FOO5 2FOO1FOO9 $ OUTPUT: $ cat a.txt | sort SOMEMAGIC 2FOO1FOO9 1FOO2FOO3 4FOO5FOO5 $ Question: How can I sort, if I have a several character long ...
2
votes
4answers
437 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 ...
2
votes
2answers
83 views

Removing lines with a single common field

I have a tab separated file that looks like this: 123 some text 123 some different text 334 some other text 341 more text and I want to do two things. One is to order everything numerically ...
2
votes
2answers
131 views

Printing lines with similar text together

I am currently working on analyzing the performance of an application. I've starting by looking at the logs generated by our application and identifying the business logic tasks that are taking more ...
3
votes
3answers
346 views

Sort comma-separated fields on each line by numeric value

I tried this: $ echo "2,3435,1" | sort -n 2,3435,1 $ sort -t',' -n test_sort.txt kill,gill,burger 110,20,30,13 $ cat test_sort.txt 110,20,30,13 kill,gill,burger Why doesn't my sort command work? ...
1
vote
3answers
45 views

How can i get the process with the biggest pid?

How can I get the process with the biggest pid using ps?
7
votes
4answers
194 views

Sort fields inline

I'm trying to sort within a line of input over an unknown number of fields: Input: ab bc bc ab cd ef bc bc cd ef cd bc ab ef ab bc cd gh Output: ab bc ab bc bc cd ef bc cd ef ab cb cd ab bc cd ...
8
votes
2answers
236 views

sort by hex value

Using coreutils sort, how can I sort numerically by a hexadecimal value (field)? I was expecting something along the lines of sort -k3,3x file_to_sort however, such an x does not exist. Edit: ...
11
votes
3answers
701 views

Sorting data faster approach

I need to sort a bed file randomly 10000 times and take the top 1000 rows each time. Currently, I am using the following code: for i in {1..100}; do for j in {1..100}; do sort -R ...
2
votes
3answers
67 views

Get the last minute dated lines from list

If I have an input file with a list of users and their dates they were last signed in, how can I select with a sort | awk function the last minute lines? The dates are written in a +%H:%M:%S format. ...
-1
votes
1answer
25 views

How do I sort the signal buses with bits in ascending order?

I am trying to sort a file with signal buses. I am looking for result where the bits are in ascending order -- 2 followed by 3 and not 20. cat file1 |sort file1 cls_16_snap[2] cls_16_snap[20] ...
2
votes
1answer
39 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 ...
2
votes
2answers
94 views

How to print top five highest numbers from a column?

I have a text file with four columns. I need to read till end of file and print the highest number from column3 (top 5 values) along with column 1. input.txt xm|340034177|ref|RT_235820.1| 139697 ...
1
vote
2answers
107 views

Sort files into directories named by prefix of file

I have a bunch of files like this 5830_1.png 5830_2.png 5830_3.png 5831_1.png 5832_1.png 5832_2.png I'd like to sort these files all into directories that take the prefix of the file name as the ...
20
votes
6answers
8k 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
1answer
65 views

`sort` disregards question mark [duplicate]

I need to sort a file based on names in the first column. Some of the names end in a question mark. sort persistently ignores this question mark during sorting: sort -k 1 -t , <<TEST a?,1 a,2 ...
7
votes
1answer
560 views

Is gnu coreutils sort broken?

Consider the following input to sort: cat > foo <<EOM D,,5014978 DD,,25 D,I,1972765530 D,Y,4223624 -,Y,71285059 YA,I,2 EOM Now try running sort foo The output is not sorted when trying ...
2
votes
2answers
174 views

Tool for viewing top N items in stream

I'm looking for an existing Linux command-line tools that can accomplish the following: Consider there is an input stream /dev/inputstream which spews an infinite stream of data that looks like this: ...