Skip to main content

Questions tagged [sort]

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

Filter by
Sorted by
Tagged with
4 votes
1 answer
196 views

Suppose we have a script named test_sort in our $PATH with the following contents: #!/bin/bash function echo_text () { printf -- "%s\n" "$fc$oc$fs$lc" printf -- "%s\n&...
Melab's user avatar
  • 4,476
4 votes
3 answers
301 views

I am trying to sort the output of ls by a certain part of the file names. The files are named like this: file1-2025-09-30.tgz file1-2025-10-01.tgz file1-2025-10-15.tgz file2-2025-09-30.tgz file2-2025-...
weka's user avatar
  • 53
5 votes
0 answers
144 views

In Nautilus (Debian 12, en_US.UTF-8, GNOME Files 43.2), the following eight files are sorted in the following order: - -1 -- --1 1 --a -a a To answer the question (Why does Nautilus sort these files ...
user769759's user avatar
1 vote
1 answer
123 views

I use fd to find file names containing only zeros. I want adopt this code to work with all files in folders, not with the only one file... This works not bad $ fdfind -tf -x bash -c '[ -s {} ] &&...
Андрей Тернити's user avatar
4 votes
2 answers
615 views

Here is my simple test file: # cat test grp_pt cmg grp_pt compsc grp_pt ffre grp_pt grp_pt grp_pt hpcedt grp_ptix dsnlp grp_ptix exinspect grp_ptix ptix grp_ptix sciml grp_ptix vers grp_ptix ...
Thu-Ha Tran's user avatar
2 votes
0 answers
90 views

I have a 4 TB hard drive containing pictures, sounds, and videos from the last 15 years. These files were copied onto this drive from various sources, including hard drives, cameras, phones, CD-ROMs, ...
Bernd Kunze's user avatar
3 votes
1 answer
259 views

I have a file named test with the following content: 12288 4096 505 Note that there's a single space before 12288, two spaces before 4096 and three spaces before 505. When I run GNU sort -k1.1,...
russell.price's user avatar
5 votes
2 answers
403 views

I can't solve what I want using the tree, du, or df commands. I'm using: du version 9.6 tree version 2.2.1 What I want: For the current directory, list all directories recursively to a depth of 3, ...
user2718593's user avatar
0 votes
1 answer
56 views

I have this file 1 you 3 me 2 their 4 us this pipe works fine (it order first column by number, second by letters) is a pipe of another user found here paste <(awk '{print $1}' file.txt | sort ...
elbarna's user avatar
  • 14.5k
9 votes
2 answers
1k views

The title is a summary of what I'm trying to achieve, but I'll give an example to illustrate what my problem is and how I've been trying to solve it. Example folder Let's say I've got a folder on a ...
Apollucas's user avatar
0 votes
3 answers
138 views

I am using Arch Linux/Debian Linux and want a list of unique "identifiers" in an ASCII txt file. Here is a snippet of the data I want to whittle down: ... (Received from VRW): wind ... ... (...
Zac Helmberger's user avatar
0 votes
1 answer
54 views

With this cmd line I see processes and use of ram in mb ps aux | awk '{print $6/1024 " MB\t\t" $11}' | sort -rn|less The problem is the sort 9.95703 MB /usr/lib/systemd/systemd-...
elbarna's user avatar
  • 14.5k
4 votes
1 answer
119 views

Those 2 sequences of lines are not sorted the same by the Linux shell command sort (gnu-coreutils 8.22 under RHEL 7.8), even though they begin with the same distinct prefixes. Why ? $ echo "f'*.5....
Francois's user avatar
  • 247
-5 votes
1 answer
74 views

After I wrote prompt $ sort display doesn't shown anything what the next step?
Wahyu Irawan's user avatar
1 vote
1 answer
116 views

I have a software module which contains some files with same pattern. <whitespaces>private static final long serialVersionUID = \dL; How can I find files with the same value? $ grep -R ...
Jin Kwon's user avatar
  • 564
2 votes
1 answer
544 views

I would expect that the -g flag tells sort to treat the fields as floating point numbers, but: cat << EOF | sort -g -k1,2 0 0 0 1.0 0 .5 0 5.0 EOF gives 0 0 0 1.0 0 .5 0 5.0 Therefore the .5 ...
cipper's user avatar
  • 385
0 votes
2 answers
265 views

I seem to be having the same issue as described in The "join" utility reports: file is not sorted, but in fact it is sorted however I have piped BOTH files through sort before attempting to ...
symcbean's user avatar
  • 6,359
-2 votes
2 answers
177 views

I have two files containing the similar pattern: cmd1 [cmd2 {xx/xx[7] x/x[0] ...}] cmd3 [cmd4 {xx/x[12] ...}] cmd5 [cmd6 {x/x[1] xx ...}] I don't need to consider all the cmds in two files. Only need ...
Alan Gatsby's user avatar
10 votes
3 answers
2k views

The GNU sort command is not sorting words of different lengths with common prefixes correctly for me, but only when using a field delimiter to sort on one of multiple fields. Here is the correct, ...
Ben McIlwain's user avatar
0 votes
0 answers
12 views

I'm wondering where this data is being stored. I am running these commands from a different file system, but / seems to increase and I'm not sure where the data is. cd /different_fs cat a b c | sort | ...
CrackerJack9's user avatar
1 vote
1 answer
198 views

I am trying to count how many times I use a certain version of a library on my computer. For some reason, uniq -c is outputing duplicates, despite sorting it, and despite the sort order seeming in ...
Albert's user avatar
  • 171
-1 votes
1 answer
103 views

I'm working with my .bash_history file and want to identify repetitive commands for cleanup. Here's a sample snippet: ... #1713251479 sh lowbat.sh #1713251495 nvim lowbat.sh #1713252186 sh lowbat.sh #...
ReYuki's user avatar
  • 33
1 vote
3 answers
862 views

I want to loop over all files in directory on macOS and perform some operations on each file, and do this based on their size, going from big to small. To create a list I can loop over I do this: ...
d-b's user avatar
  • 2,077
6 votes
2 answers
827 views

I have a very large file which I want to sort alphabetically. It is a tab separated file, but I really need to be sure that the file is sorted starting by the first character in the line regardless it ...
True Soft's user avatar
  • 163
6 votes
2 answers
2k views

I'm tracking the configuration of some system in JSON format in a revision control system. Unfortunately that configuration is retrieved using some closed-source proprietary command, and the output ...
Stéphane Chazelas's user avatar
5 votes
5 answers
470 views

So I have a file full of test commands that I like to run against some of my functions to make sure they are handling all possible situations correctly. No point in having duplicate commands tho. ...
Ray Andrews's user avatar
  • 2,615
3 votes
1 answer
125 views

Having a read loop that manipulate data from another function. One of the tasks in the loop is to record widest text in "some columns". At the end of the loop the width is printed out, but ...
Darkthrone's user avatar
2 votes
1 answer
202 views

Scenario: # on Linux $ cat r456.txt e+e+l e+e-c $ cat r456.txt | sort e+e-c e+e+l $ sort --version sort (GNU coreutils) 8.30 # on Cygwin $ cat r456.txt e+e+l e+e-c $ cat r456.txt | sort e+e+l e+e-...
pmor's user avatar
  • 757
6 votes
3 answers
1k views

I have a two-column file that you can create as follows cat > twocol << EOF 007 03 001 03 003 01 137 12 001 11 002 01 002 02 002 03 001 02 002 04 137 94 010 21 001 01 EOF The resultant file, ...
bballdave025's user avatar
0 votes
1 answer
903 views

The main answer of Sort the files in the directory recursively based on last modified date gives a method to list all files in a directory, recursively, sorted by modification date: find -printf "...
Basj's user avatar
  • 2,639
0 votes
2 answers
57 views

I am on Ubuntu 22, and I have a large tree of files with annoying names that include numeric values in a variety of positions. Something like: ./2 ./2/9 ./2/10 ./2/8 ./1 ./1/2 ./1/1 ./1/11 ./11 ./11/...
superstator's user avatar
1 vote
4 answers
93 views

I have a list of data, separated into blocks by headlines. The headlines are marked by 6 '=' signs at beginning and end. There is a limited set of headlines that may appear, but not all of them appear ...
Knuschberkeks's user avatar
6 votes
3 answers
1k views

I'm reading this blog at the moment: https://www.baeldung.com/linux/dir-find-largest-file-recursively And I am asking about this command: find /usr/lib -type f -printf "%s\t%p\n" | sort -n | ...
achhainsan's user avatar
4 votes
4 answers
425 views

I have two lists with item numbers and want to mark the difference between these lists by writing the numbers wich aren't in both files in a new file. Both Files have the item number in column 2 and ...
user avatar
0 votes
1 answer
173 views

I am using ls on MacOS 11.6.1. In the output, the Upper cases are displayed before the lower case. For example, I get the following output: $ ls Blabla.txt GAGAS.txt asdf.txt blabla.txt and would ...
ecjb's user avatar
  • 495
5 votes
2 answers
254 views

I've run into a bit of a weird behaviour that I don't fully understand with ls and Chinese filenames. I'm running macOS 13.6.1 with SIP enabled (no core OS modifications), MacPorts installed, and US ...
nneonneo's user avatar
  • 1,198
4 votes
4 answers
577 views

Is there a way to sort the list of positional parameters in POSIX sh? Each positional parameter could contain arbitrary characters (e.g. spaces, newlines, tabs, etc.). The sort algorithm should be ...
Flux's user avatar
  • 3,318
0 votes
1 answer
163 views

I have a folder is populated each day with a series of files, for example content1_20231110.csv, content2_20231110.csv, etc. For reasons out of my control, this folder holds an entire year's worth of ...
Sam McAlevy's user avatar
1 vote
1 answer
791 views

I noticed that Nautilus(GNOME Files) does not fully sort alphabetically. $ touch 1 $ touch 2 $ touch 3 $ touch '!2' Then the files are displayed in the following order: !2 1 2 3. This is fully ...
lv04438's user avatar
  • 11
0 votes
2 answers
163 views

I need to load multiple files in my shell script with the same filename but appended in the front of each file name is YYMMDDPERSONNEL Examples: 231102PERSONNEL and 230103PERSONNEL There are many ...
teejay's user avatar
  • 9
-2 votes
2 answers
184 views

I have a text file containing paths of various wav files. But when they are created they are sorted based on alphabetical order. Hence the paths are like this /home/wav_path/...
Turing101's user avatar
  • 153
0 votes
3 answers
90 views

When I don't remember where a file or a folder is, I sometime use the locate command (that finds more occurrences, allow more candidates than a find, in my mind. But maybe I'm mistaking). But then ...
Marc Le Bihan's user avatar
1 vote
4 answers
292 views

I am using nsxiv to view JPEG and PNG images on FreeBSD. However, I am unable to find a way to sort and filter the images by modification time to view them in nsxiv on FreeBSD. On Linux with GNU ...
Flux's user avatar
  • 3,318
0 votes
3 answers
221 views

I have a text file with book name and chapter in the bible. I would like to sort the lines so that lines are first sorted according to the order between their books, the lexical order between the ...
Tim's user avatar
  • 107k
0 votes
0 answers
19 views

I have a csv (Fieldseparator is the ',') file with data in it and I would have to prepare the csv before reading it (mainly just sort it) into variables. How can I read the sorted stream into ...
roediGERhard's user avatar
1 vote
3 answers
123 views

How do I ls files in a directory beginning with a particular filename? For example, if my CWD has these files: $ ls -1 alpha.mp3 bar.xls file1.txt file2.txt foo.odt testing3.txt How do I print out ...
Geremia's user avatar
  • 1,250
0 votes
1 answer
44 views

So, let's say I have a script that uses find to print paths with null-terminated filenames. I also want to print another version of the output where each path is sorted by its basename. I want to ...
Eduardo Perez's user avatar
1 vote
1 answer
213 views

I have a file containing a list of both IPv4 addresses and /24 networks. The IP addresses are already unique and sorted by all four octets. I would like to use bash to group the addresses that belong ...
Luca's user avatar
  • 21
3 votes
3 answers
415 views

I have file output in a CSV file I want to sort by date time but the date time appears as below, with the time and year appearing in a different order. Using this command to produce the file listing: ...
Steve's user avatar
  • 31
0 votes
3 answers
830 views

ASK: to use cut command to list all users to confirm a successful useradd. ISSUE: The list was very long and I had to scroll through output to find user. NEED: Sort by the date the user was created. ...
VintageDroid's user avatar

1
2 3 4 5
21