Questions tagged [sort]

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

Filter by
Sorted by
Tagged with
0 votes
1 answer
34 views

sort numbers according to last number in line [duplicate]

the following is file example 585.3 M netG ple jdhe jdhe_daily se 1732 pcv DC month 202204 day 20220413 585.5 M netG ple jdhe jdhe_daily se 1734 pcv DC month 202204 day 20220413 585.8 M netG ple ...
user avatar
  • 10.9k
0 votes
2 answers
30 views

How to use Bash globbing in combination with the brace expansion (in sort)?

I use sort to remove duplicate lines from text files, sort in alphabetical order, overwriting the files ({,} in the command): sort -u -o $HOME/Documents/notes/URLs.txt{,} How to add additional files ...
user avatar
0 votes
3 answers
54 views

de-duplicate list but group parts of it

I am compiling some access rules from failed logins and after some piping I arrived at this: cat <<INPUT | sort -k 3,3 --unique Deny from 13.42.98.142 # demo Deny from 13.42.98.142 # test Deny ...
user avatar
2 votes
1 answer
77 views

GNU Linux "sort -g" can hang indefinitely when run on standard input (on Ubuntu)

The following command (on Ubuntu 20.04 and 22.04): dd if=/dev/urandom count=800000 bs=1 | od -An -t f4 -w4 | sponge | sort -g Can hang indefinitely, with the GNU sort command taking 100% of the CPU. ...
user avatar
  • 121
-1 votes
2 answers
29 views

how to sort a file having rows of values separated by space?

I have a text file with rows of latitudes and longitudes like so: 17.7003 17.7003 17.7004 17.7004 17.7005 17.7005 17.7005 17.7006 17.7006 17.7006 17.7007 17.7007 17.7008 17.7008 17.7008 17.7009 17....
user avatar
4 votes
4 answers
503 views

How do I sort binary key value pairs at fixed byte offsets using the Linux sort utility?

I want to sort a 20GB binary file that contains 30-byte key and 20 byte value placed in a contiguous manner. Everything is on a single line. I would like to specify the key length the sort must use ...
user avatar
1 vote
1 answer
59 views

What happens when the sort command is provided with with key range in descending order?

I am trying to understand something about the "sort" command and I am struggling. I would appreciate some help here. I do have a file called "my_file.csv" with the following ...
user avatar
14 votes
2 answers
4k views

Who killed my sort? or How to efficient count distinct values from a csv column

I'm doing some processing trying to get how many different lines in a file containing 160,353,104 lines. Here is my pipeline and stderr output. $ tail -n+2 2022_place_canvas_history.csv | cut -d, -f2 |...
user avatar
  • 193
1 vote
2 answers
48 views

Join two files ordered numerically according to second column

I have two files file 1 contains 2*J=0 EXP= 0.00000 2*J=4 EXP= 1.27911 2*J=8 EXP= 1.57613 2*J=12 EXP= 1.69134 2*J=10 EXP= 2.72705 2*J=16 EXP= 4.55689 2*J=20 EXP= 5.62138 file 2 contains 2*J=0 EXC= 0....
user avatar
0 votes
0 answers
19 views

org.x.apps.favorites.list does not respect sort/display order in Cinnamon

The schema settings summary says "List of favorites, stored in display order", but the 'star' app in the panel (favorites@cinnamon.org) shows the correct URIs, but not in the display order. (...
user avatar
  • 13
1 vote
1 answer
37 views

How does -m option work in sort command?

As sort's man page says: -m, --merge merge already sorted files; do not sort Here are my two simple text files and the result of sort command with -m option: soroush@pop-os:~/Desktop$ cat a_file....
user avatar
  • 113
0 votes
2 answers
27 views

Sorting by fourth column

I have a CSV file filename.csv with the following contents. filename.csv: "Afghanistan","94.0","81.1" "Bahamas","42.9","43.2" "Bolivia (...
user avatar
  • 11
0 votes
1 answer
27 views

Command to Sort by second column and Omit first two rows

I have a CSV file filename.csv with the contents. ,"Range 1 (%)","Range 2 (%)" "Color","Number Color 1","Number Color 2" "Red","99.0&...
user avatar
  • 11
0 votes
1 answer
38 views

Why did sort -u removed duplicates only in pipe?

In this command, sort -u removed duplicates. curl https://en.wikipedia.org/wiki/Help:Special_page -s | grep -oP 'Special:\K[a-zA-Z0-9]*' | sort -u > special_page_names In this command, it didn't. ...
user avatar
  • 115
0 votes
1 answer
23 views

Convenient way to have selected files shown in the beginning of file lists in file managers?

In Windows if one wishes certain file (or directory) to be shown in the beginning of file lists in a file manager (no matter which one, really), one may choose to put the underscore character in the ...
user avatar
  • 61
0 votes
3 answers
26 views

Sort files by LoC - sort not working when piped from wc -l

I'm trying to sort a directory of files by LoC. But sort appears to do nothing if the lines are piped in: paths=`find ./src/ | egrep "\.(cpp|h)$"` for path in $paths; do wc -l $path | sort -...
user avatar
3 votes
1 answer
96 views

How do I remove anagram duplicates from a list?

I have a tab-delineated .csv with strings and descriptions. A bit like this: strap tight elba Island foo bar able Cain parts buy able Cain First, I'm sorting the file by length of ...
user avatar
  • 31
0 votes
3 answers
55 views

How to sort a file contents after n lines?

In linux we can run sort command to sort file contents, but in my case I have the following file (THANKS.txt): These people have contributed to OSN Envoy. We always try to keep this list updated and ...
user avatar
  • 129
0 votes
2 answers
39 views

Sort absolute directory path alphabetically and numerically

I am having difficulty finding solutions online to sort an absolute directory path using letters and numbers. Example is the below in a file called test.txt /opt/informix/data/dcdwhdev/rootdbs.2 /...
user avatar
0 votes
1 answer
65 views

Sorting lines based on certain digit pattern

Assume I have a text file with the following lines: 192.168.1.1.55555 192.168.1.1.55555 192.168.1.1.5555 192.168.1.1.555 192.168.1.1.55 192.168.1.1.55 192.168.1.1.5 8.8.8.8.4433 8.8.8.8.443 8.8.8.8....
user avatar
0 votes
2 answers
49 views

Sorting Stanzas in a text file

I have a file containing many stanzas in the following format. Please note the blank line in between each stanza. I would like to be able to sort this file so that the finished file is each stanza in ...
user avatar
0 votes
0 answers
24 views

Using grep and mediainfo together

I'm trying to build a list of movies with the metadata name and the file path. This is my statement so far: find ~/Videos/Movies/ -type f -exec mediainfo {} \; | grep -E 'Movie name|Complete name' | ...
user avatar
  • 1
0 votes
1 answer
33 views

Sorting long list of files into multiple sub directories based on name

I have a group of 1000+ files that are labeled using text and date in a folder /home/dir/dir2/oldspot with below format: File taken on 01/07/2020 at 23:08 elevation 5 is aaaaaa-bbbb-cc10dddd-L1-...
user avatar
0 votes
2 answers
56 views

Sorting list with pipeline and without ls-lS command

The Linux program ‘sort’ can sort a file, or the output from another program. How do I use sort to sort the output of the ls command by 1) file name 2) file size. I know there are options of the ‘ls’ ...
user avatar
  • 21
5 votes
3 answers
178 views

Multiple column alphabetical and numerical sort

I want to sort based on the file name. For the case where the file name prefix matches and the file ends in a number, I would like to have those numerically sorted based on the number at the end of ...
user avatar
  • 1,393
0 votes
1 answer
111 views

get count of lines while in pipe

i have a bash script that looks like this: some_process | sort -u | other_process >> some_file I'd like to get the line count to while i'm streaming the data, after the data is sorted but ...
user avatar
  • 195
-1 votes
1 answer
191 views

remove duplicate lines across multiple txt files [closed]

I have 12 text files all in one folder, each with about 5 million lines, each file has no duplicate line on its own but there are duplicated across multiple files, I want to remove the duplicate lines ...
user avatar
0 votes
2 answers
81 views

sort by column not working as expected

cat marks.txt returns 1) Amit Physics 80 2) Rahul Maths 90 3) Shyam Biology 87 4) Kedar English 85 5) Hari History 89 awk -F" " '{ print $4"\t" $0 }' marks....
user avatar
  • 411
1 vote
0 answers
50 views

How to use the unix command "sort" with user-defined collation list?

Background: The kanji ideograph character sorting / encoding sequence in GB2312, GB18030-2005, GBK, Big5, CNS-11643 varies and are different to how they get sorted in Unicode (incl. UTF-8). As of ...
user avatar
0 votes
2 answers
49 views

Passing options to any linux programs from variables [duplicate]

Desired code: echo "$var" | sort -t/ -k 1,1n -k2,2n -k3,3n Case scenario: options to sort arr dynamically created based on condition and stored in variables. How can i pass them. option='-...
user avatar
-1 votes
2 answers
87 views

Script for counting and summarising Numbers & Unique numbers in each line

timestamp : IDs returned 20160420084726:- 20160420085418:[111783178, 111557953, 111646835, 111413356, 111412662, 105618372, 111413557] 20160420085418:[111413432, 111633904, 111783198, 111792767, ...
user avatar
  • 11
0 votes
0 answers
43 views

Why is sort -u -n losing non-unique lines? [duplicate]

I was trying to sort a list using numerical order, and only keep unique lines, and thought sort -n -u would do the job. But surprisingly enough, this removes non-unique lines. Am I missing something ...
user avatar
0 votes
1 answer
35 views

Properly handling sort crashing due to out of disk space

I run sort on large files (think 500GB+) on a HPC system. Multiple sorts may be running on a single node, and when the 370GB RAM limit imposed on sort jobs is exceeded, sort goes to a 1TB /scratch ...
user avatar
1 vote
2 answers
68 views

How to sort by the whitespace character

I have this shell script which lists all the names of subdirectories of the current working directory. Is there any way I can sort the names so that directory with whitespaces in the name comes first ...
user avatar
  • 11
1 vote
1 answer
86 views

ls and sort by number for human

I create catalogs mkdir site_{1..44}. I want to sort them site_1 site_2 site_3 site_4 ... site_44 I execute the command ls | sort -h and I have site_1 site_10 site_11 site_12 site_13 site_14 site_15 ...
user avatar
  • 39
0 votes
1 answer
182 views

Sorting lines in nano?

Is it possible to sort a selected area of text alphabetically using the nano editor? ( similar to the F10 in xed ) I use Linux Mint 20 , nano 4.8 Thank you
user avatar
-2 votes
2 answers
106 views

sort and delete older file

How can I sort the below files based on the date and time inside the folder and delete the older ones and keep the most recent ones in Linux? I just want to keep the latest one regardless of the ...
user avatar
  • 25
1 vote
3 answers
101 views

How to sort in dates in linux based on day, date, month, and year

I am trying to sort dates (like in the format below) and cannot get them in order based on the day, date, month, and year. I have tried a few different ways and have come up short. Any input would ...
user avatar
2 votes
2 answers
147 views

Find pattern: sort and delete older files

I want to delete old files and keep only the most recent from each file pattern based on the first five characters (aa_te, bb_co, cc_co, dd_xy) and the date and time in the file name. Note: All files ...
user avatar
  • 25
2 votes
1 answer
123 views

What's the difference between "sort -n" and "sort -g"?

What is the difference between the two sort options -n and -g? It's a bit confusing to have too much detail but not enough adequate documentation.
user avatar
2 votes
4 answers
174 views

Linux sort and cut multiple columns

I have the following file named "info": White:73:Mars:1543:Manuel Green:17:Jupiter:1968:Sebastian Blue:24:Venus:1970:Anna Red:35:Neptune:1122:Javier Yellow:135:Earth:1234:Raymond I need to ...
user avatar
1 vote
1 answer
56 views

How to display a sorted list of files that contains certain string in linux terminal

Assume I have 3 folders in different directories, some of them containing some more subfolders, and in each folder/subfolder I have text files named test1, test2, test3 etc..., which contain the ...
user avatar
0 votes
1 answer
66 views

Sorting a table with a non-newline record separator in bash

I have a table that looks like 'a;b;f|d;e;c|g;h' which I wish to sort by the third column. The output should be 'g;h|d;e;c|a;b;f' If I were to use the standard delimiters whitespace and newline then ...
user avatar
  • 367
0 votes
2 answers
38 views

Sort line based on the value of a column

I have to sort a thread dump which looks like this: $ jstack -l 5213 | grep cpu "Reference Handler" #2 daemon prio=10 os_prio=0 cpu=2.21ms elapsed=478.03s tid=0x00000000013bb800 nid=0x1465 ...
user avatar
1 vote
1 answer
19 views

Wrong file ordering in MySQL Docker image with Debian as base

My problem is relatively simple as I try to make a migration with the help of the Flyway CLI. The problem here is, that the system orders the migration files in the wrong order and my new file isn't ...
user avatar
0 votes
3 answers
144 views

Sorting filenames with a number of '-' delimiters

I want to sort a set of files with the same number of '-' delimiters in each filename (with -n for numeric sorting). Here is an example list /home/flora/edvart/docs/schimmel-01.png /home/flora/edvart/...
user avatar
  • 155
3 votes
1 answer
55 views

Sorting ls output respecting locale but not ignoring nonalphanumeric characters

Let's say I have a directory with the files _b, a, c, č, d. I would like to sort the files according to the cs_CZ.UTF8 locale but without ignoring the underscore, ie like this: _b a c č d. Currently, ...
user avatar
1 vote
0 answers
162 views

"Sort" command using ascii order [duplicate]

I would like to use sort to sort by ASCII value, or at least by not disregarding punctuation, i.e: sort <<DATA a.01 a.04 a2 a.3 a.2 DATA Should produce a.01 a.04 a.2 a.3 a2 Especially these ...
user avatar
  • 11
0 votes
2 answers
40 views

Sort numbers containing underscores in numeric order

I have data like below, want to sort this value by numeric order. this command didn't work. sort -t'_' -nk3,2 c Input Data 5_5_1_2 5_5_1_3 5_5_1_4 5_5_1_5 5_5_2 5_5_3 5_5_4 5_5_5 5_6 5_7 6_1_10 ...
user avatar
  • 310
1 vote
2 answers
102 views

Sort according to the last column (or any other column with a numerical value) of a csv file

I have a file with following contents. I am looking to sort this file based on the last column (and third last but for another file) while retaining rest of the contents of the row. ABC,DEF,GHI,-5,-8,...
user avatar

1
2 3 4 5
19