Questions tagged [sort]
Sorting text files or other data, for example with the sort utility.
994
questions
0
votes
0
answers
25
views
Sort by bring back results with only 3 columns [closed]
I created a text file with a list of names, some first and last, and a few with first, middle and last. I would like to sort alphabetically but only the results with first, middle and last and exclude ...
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 ...
1
vote
3
answers
61
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 ...
0
votes
1
answer
26
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 ...
1
vote
1
answer
54
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 ...
3
votes
3
answers
296
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:
...
0
votes
4
answers
62
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. ...
5
votes
6
answers
1k
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.
...
0
votes
0
answers
26
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 ...
0
votes
1
answer
61
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?
0
votes
1
answer
24
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
...
2
votes
3
answers
97
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/...
0
votes
1
answer
23
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 ...
0
votes
0
answers
56
views
How to make Gnome Nautilus sort files in lexicographic order?
I have three pdf files in a folder. They are named 01.pdf, 1.pdf and 2.pdf respectively. When I click Name on the GUI to sort the files by name in ascending order they are sorted 1.pdf, 01.pdf, 2.pdf. ...
4
votes
4
answers
263
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 ...
1
vote
2
answers
69
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 ...
0
votes
1
answer
51
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
use[email protected], 1.66 MB
[email protected], 0 ...
1
vote
3
answers
58
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 ...
0
votes
0
answers
27
views
Why would leading left parenthesis be ignored by the sort command? [duplicate]
Note the sort command has no effect. The items with leading left parentheses should be together.
What am I doing wrong?
$ cat strange
(ADJP
ADJP)
(ADVP
ADVP)
$ sort strange
(ADJP
ADJP)
(ADVP
ADVP)
$ ...
-3
votes
3
answers
97
views
CSV sort by column 3 and counter in front
I would like from this table
"ResNR";"ResNAME";"CustomerNAME";"CustomerID";"Date";"";"";"";"";"";&...
0
votes
2
answers
223
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 ...
-1
votes
1
answer
138
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....
0
votes
2
answers
239
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 ...
1
vote
2
answers
144
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|...
0
votes
1
answer
63
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}\...
0
votes
1
answer
51
views
Pipe containing sort and awk writes too many files to disk while taking random lines from files and ultimately fails due to unavailable storage
I have around 500 GB free disk space on my SSD. I'm trying to run an operation on 10 gzipped files (each around 25GB in size). But I keep running out of storage when I do it in a parallel for loop ...
3
votes
2
answers
521
views
Why does `htop` display `$'\t'` as `?` in `sort` command?
I was running a pipe command with one section being the following:
sort -t $'\t' -T . -k1,1g
When I was monitoring htop I saw this instead:
What is the reason behind this? Does this mean my command ...
5
votes
4
answers
381
views
Sort by 3 different columns with numbers and text aix
I am trying to perform a sort by 3 different columns in the correct order on an AIX system.
The below is an extract of a larger file that displays the longest running runtimes between the open ...
-1
votes
2
answers
598
views
Commands runs in shell, but not in script: no directory found error
I have a few commands that don't run as a script.
It's supposed to create a bulleted list of the file names, then sort the columns of each file alphabetically, grab the second and its matching third ...
1
vote
2
answers
204
views
sort by number & character in reverse?
I have a list of files like:
100119329_d01.png
100119329_d08.png
100119329_d02.png
100119329_d05.png
100119329_d03.png
100119329_d04.png
100119329_d07.png
100119329_f02.png
100119329_f01.png
I want ...
9
votes
1
answer
488
views
What value for LANG should I use for "sort -u“ correctly handle Chinese characters?
The context
Issues found
Issue no. 1
Issue no. 2
Issue no. 3
The question
The context
Today, I wanted to keep the unique lines in a file containing Chinese characters. I decided to use the sort ...
1
vote
4
answers
257
views
Remove rows when a specific column value is present more than once
I am processing a lot of .tsv files through awk and I need to remove all the rows where we observe duplicates or more of the same values in column 2.
E.g.
a b c
value1 2 3
value2 2 5
value3 1 9
value4 ...
4
votes
2
answers
388
views
Sort by column group and ignore other columns failing for this example, why?
I cannot work out why sort is not working correctly for this, but it's sorting based on columns I'm telling it not to. I want to sort with priorities first by column 3, then column 4, then column 5, ...
0
votes
0
answers
233
views
How to sort text file lines in ASCII order?
Let's say I have the following file.txt:
foo-a baz
foo bar
foo-c baz
If I run sort file.txt, I get the same output:
foo-a baz
foo bar
foo-c baz
Since (space) is before - in ASCII, I expected the ...
2
votes
1
answer
155
views
/bin/sort appears to ignore forward slashes in its input
I'm running Ubuntu 20.0.4.
Consider these contents of the following file (suppose the file is named input) ...
/zzzzz foo bar
/hij zzz
xyz abc
/abc
ijk lmnop
qwer tyuiop
abc def
If I run /bin/sort ...
1
vote
1
answer
208
views
How to sort a list of strings that contain a combination of letters and numbers
I want to sort following strings by the number and remove duplication in a file
cat311
celine434
celine434
celine5
jimmy12
john44
john41
to be
celine5
jimmy12
john41
john44
cat311
celine434
0
votes
1
answer
232
views
Trouble creating for loop with multiple commands to read csv files
I'm trying to create a for loop that reads prints the file name, alphabetizes fields, and adds html tags that would ultimately create an html file that looks like
<h3 id= filename> file </h3&...
0
votes
2
answers
136
views
Compare files with similar names by size between folders
I have two folders with thousands of files each. One folder from last year with a letter and the year prefix for each file (a2020abc123.txt), and the same file for this year in another folder with the ...
1
vote
2
answers
82
views
Arranging the lines in required order
A file contains lines as follows:
acb/xyz/row<t>
acb/xyz/row<t>
abc/xyz/row<1>
abc/xyz/row<1>
abc/xyz/row<0>
abc/xyz/row<0>
abc/xyz/row<3>
abc/xyz/row<3>...
0
votes
0
answers
26
views
numeric sort with unique option does not show 0! [duplicate]
I have a file with many redundant numbers in each row. Imagine something like the below:
echo "10
9
5
6
4
cell
3
2
0
7
0
1" > test
When I use sort -un test I get the following output:
...
12
votes
2
answers
1k
views
Why does sort have an --output= option?
sort -o seems superfluous. What is the point of using it when we can use sort >?
Is it sometimes impossible to use shell redirection?
2
votes
2
answers
753
views
Date sorting format: Day-Month-Year
I have a text file with date value.
Data:
01-Sep-21
02-Jan-22
12-Aug-21
24-Dec-21
11-Jul-22
How to sort these data from old to new date value?
0
votes
1
answer
87
views
Find the highest number after specific string from mutiple files
Each file has similar content:
number 1:
asdfa11sdfsadf
number 2:
asdfa12sdfsadf
number 1:
asdfa1sdfsadf
number 3:
asdfa33sdfsadf
return
3 or number 3: are equally good.
Have tried:
max="$( awk ...
0
votes
0
answers
413
views
Writing a File with CSV Header Column and Unique Column Values in Bash
I have a bunch of csvfiles that I'm importing into a database. I'd like to get a preview of the unique values in each column to help me create the tables. I've written a script that takes a input csv ...
4
votes
2
answers
680
views
sort command- numeric sort not working on csv
GNU sort on Linux is not giving expected results on my csv file. Can you please help to resolve the situation/ issue?
Input file
[nscruser]$ cat cemp1.txt
10,30
50,900
20,1050
Objective I need to do ...
6
votes
1
answer
925
views
"sort -h" not working correctly
I tried sorting this file :
1000000911M
1G
2G
1.5G
100M
but using sort -h file I got :
100M
1000000911M
1G
1.5G
2G
Is there a problem with sort? If so how to avoid that without having to explicitly ...
0
votes
0
answers
710
views
The total size of the argument list and exported variables exceeds the OS limit of 1MB
I was doing a grid search for some scientific computing project, and got a bunch of log files with parameters embedded in the filenames.
$ ls -l | wc -l
38210
$ ls -l | tail
-rw-rw-r-- 1 qys ...
-2
votes
3
answers
51
views
cert expired report per date
Hi How can i sort below file so as to have cert expiration date is used to sort this, thanks
Cluster10* expire date: Feb 22 23:59:59 2024 GMT
Cluster11* expire date: Feb 1 23:59:59 2023 GMT
...
0
votes
2
answers
59
views
Complete sort -u option command for a specifically removal purpose
How is a complete sort -u option command syntax for a specifically removal purpose removing any not 100% exact duplicate lines that is instead of finding exact characters in line, every line with ...
1
vote
1
answer
174
views
How do I use sort on multiple columns with different data types
Here's my tab-delimited file t.tsv:
$ cat t.tsv
2022/05/05 -258.03
2022/05/07 -18.10
2022/05/09 -10.74
2022/05/09 -132.60
2022/05/12 -18.56
2022/05/12 -20.20
2022/05/17 -11.00
2022/05/17 -112....