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
0 votes
0 answers
57 views

Sort is not sorting?

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
  • 5,821
-1 votes
2 answers
96 views

How to diff two files in bash efficiently?

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

GNU sort command does not sort words of different lengths with common prefixes correctly when using field delimiter

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
9 views

cat/sort/uniq temporary storage? [duplicate]

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
125 views

Why is sorted uniq -c command showing duplicates

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
  • 161
-1 votes
1 answer
68 views

Sorting Bash History for Redundancy Removal

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 #...
Yuki San's user avatar
1 vote
3 answers
455 views

How to sort files by size in bash script?

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
  • 1
6 votes
2 answers
667 views

Sort a file by lines, regardless of their content

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
4 votes
2 answers
124 views

sort all arrays in a JSON file depth-first to get a consistent order

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
330 views

Is it possible to sort the letters in a word in a line of text?

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,517
3 votes
1 answer
91 views

Write header as first line at end of data

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
1 vote
0 answers
37 views

Why does sort on Linux and on Cygwin return different results?

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
  • 619
6 votes
3 answers
637 views

awk: sort by first column then second; output unique 1st column once but all 2nd column

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
146 views

List all files in a directory, recursively, sorted by modification date

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,549
0 votes
2 answers
40 views

Multilevel numeric path sort

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
69 views

Reverse sorting of 2 textblocks in larger set of textblocks

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
4 votes
3 answers
969 views

How does sort -n command know what it needs to sort by in a file that contains both numbers and text?

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
366 views

Awk- Compare Numbers from Two Files and write Differences in New File

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
58 views

Display the results in an alphabetical order, independently of their case [duplicate]

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
  • 445
4 votes
2 answers
190 views

Why is ls sorting Chinese filenames by length?

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,108
4 votes
4 answers
363 views

How to sort the list of positional parameters in POSIX sh

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
  • 2,978
0 votes
1 answer
103 views

Shell script to find and copy files from a painfully large unsorted folder

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
254 views

How exactly does Nautilus sort files by name?

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
115 views

Load files in sequential order

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
126 views

Sorting a text file based on numerical values present in each line [closed]

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
64 views

Does a command exist that lists all the directories where a word appears in a file or directory name?

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
159 views

How to sort and filter images by modification time and view them in nsxiv on FreeBSD

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
  • 2,978
0 votes
3 answers
187 views

How can I sort the lines in this text file?

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
  • 103k
0 votes
0 answers
16 views

reading into variables from "piped" data [duplicate]

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
70 views

ls starting at particular file

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,185
0 votes
1 answer
31 views

Pipe null terminated file paths twice to same output, but second time sorted by basename

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
124 views

Group IP addresses belonging to the same /24 network

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
361 views

MAC OSX / Bash Problem - Sorting strings as a date

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
334 views

listing existing users sorted by date of creation using cut command

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
5 votes
6 answers
3k views

sort the whole .csv based on the value in a certain column

I have a csv file with different revenues. I want to sort the csv file on revenue from high to low value. I can't find how to do this in terminal without the use of python. I don't want to use python. ...
pwrsheller's user avatar
0 votes
0 answers
55 views

how does data flows through pipe in linux when sorting?

suppose I do something like cat afile [ | possibly awk or similar to process the file] | sort I know data flows something like afile -- stdout -- os buffer -- stdin -- sort When the size of afile is ...
eugene's user avatar
  • 101
0 votes
1 answer
88 views

What is the difference between sort < and sort without '<'? [duplicate]

Both show the sorted file without changing the original file, so what is the difference?
Sabino Lopes's user avatar
0 votes
1 answer
32 views

sort specific column in linux that have number, alphabet, and delimiter

I have been trying to sort specific column (column 2) with some data that have number,alphabetic,and delimiter in linux ( 9 million rows) chr position p-value 10 chr10:6754:SG 0.2 1 chr1:68789:SG 0.6 ...
Leila Najd's user avatar
2 votes
3 answers
126 views

Sort a list of filenames such that files in subdirectories are listed before files in the parent directory

I have a text file containing a list of files, such as: file A1/file A1/B1/file A2/file How can I sort it such that files in subdirectories are listed before other files in the parent directory? A1/...
Ken Taylor's user avatar
0 votes
1 answer
31 views

sort by two numerical columns

I am trying to sort a genetic file based on chr (column 2) and position (column 3) that both start from lower to higher. my table is like this in large file SNP CHR BP A1 A2 effect_allele_frequency ...
motor 30's user avatar
4 votes
4 answers
357 views

Collect chars from strings and print their unicode

Context (skip, if you don't care; read, if you suspect I'm totally on the wrong track) For an embedded system with small memory, I want to generate fonts which contain only those glyphs actually ...
Philippos's user avatar
  • 13.5k
1 vote
2 answers
126 views

how to list all files in a given period according their duration(not moment) of access

under linux, how to list all files in a given directory and its subdirs, in a given period, say last 10days, according their duration of access, ideally the result ought to be sorted by access ...
user2718593's user avatar
0 votes
1 answer
79 views

Trying to sort output of mailbox sized

Trying to sort an output file of mailbox sizes. [email protected], 1.35 MB [email protected], 2.19 GB [email protected], 0 B [email protected], 0 B [email protected], 1.66 MB [email protected], 0 ...
dj423's user avatar
  • 1
1 vote
3 answers
63 views

sort text file based on logic

I have .txt file which has 1000 character string per line and the file has millions of rows. Client's new requirement is to sort this file based on below logic. Thanks in advance, I am new to unix and ...
Nick's user avatar
  • 11
-3 votes
3 answers
100 views

CSV sort by column 3 and counter in front

I would like from this table "ResNR";"ResNAME";"CustomerNAME";"CustomerID";"Date";"";"";"";"";"";&...
dima1002's user avatar
0 votes
2 answers
333 views

Sort file array list in bash by date and bypass argument limit

So, I have a file array list in a bash shell, and I want to sort all the files in the array by the date modified, starting with the oldest being the first one in the array. However, I don't want to ...
Eduardo Perez's user avatar
-1 votes
1 answer
197 views

I need to compare/sort two text files

this is the scenario. I have File1 and File2 and i like to have the outcome in File3. I'm kind of new to Linux, but so far ive tried to use sort, diff, and comm. but no luck so far. File1.txt File2....
conny's user avatar
  • 1
0 votes
2 answers
498 views

Choose columns with sort and cut in a csv with a comma delimiter ',' ignoring data on quotes with comma "text,text"

I am parsing a huge csv file with rows and columns with different parameters. However, some fields contain large descriptions within quotes that contain commas. How can I choose columns with sort and ...
infinity's user avatar
1 vote
2 answers
211 views

Sorting a FASTA sequence file according to species names using sed

I have a FASTA file of 536 DNA sequences containing multiple species, but it is not necessarily in order according to species name. My headers with the sequences look like >COLFG678-14|MZ630002|...
compbiostats's user avatar
0 votes
1 answer
69 views

Sort blocks of string on file

i have lots of spells and relative description (as in rpg) not in alphabetical order. The code shown is in latex the first line of each block must contain \index{Spells} example \medskip\textbf{Aid}\...
Andres Zanzani's user avatar

1
2 3 4 5
21