Questions tagged [sort]

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

Filter by
Sorted by
Tagged with
1
vote
1answer
26 views

Bash: sort CSV on date by month,day

I've searched unsuccessfully for a solution to this problem. I have a CSV file with a date field I'm trying to sort by both month and day. CSV format : name,email,phone,date The date field format ...
0
votes
1answer
16 views

sorting text file by date column

How to sort text file by date properly in sample below? The problem is that sort -k1,1 does not really work and neither can i use the dot notation such as sort -k1.6,1.9 -k1.4,1.4 -k1.1,1.2 because ...
3
votes
1answer
45 views

Create folders with unique names of filenames

I am trying to create folders from unique filenames. Here are the files: T001 └── 20000101 ├── 6_3D-MP-RAGE_97.dcm ├── 6_3D-MP-RAGE_98.dcm ├── 5_133_VOLUMES_99027.dcm ├── ...
-1
votes
1answer
27 views

Difference between Gnu sort -k2 and -k2,2

less file.txt 01 Joe x 02 Marie y 03 Albert p 04 Dave k I want to sort by column 2. However both of the following commands give same output. It would be great to know what is the difference between ...
0
votes
1answer
45 views

Sorting file lines numerically by chromosome?

I have genetic variant data with several columns, currently my variants/lines are in the wrong order and need to be sorted by chromosome. I've tried a few ways to do this using answers from similar ...
1
vote
0answers
20 views

Difference in sorting behaviour based on LANG setting

I ran following two commands with different LANG settings : ~$ LANG= sort <<< $'x\n_y\nz' _y x z ~$ LANG=en_US.UTF-8 sort <<< $'x\n_y\nz' x _y z Can someone explain why there is ...
0
votes
1answer
18 views

sort with keeping the color coded result from pdftotext find

I have a find command that works perfectly except that it doesn't sort the results. path = path to the folder where you want to search foo = search term find /path/ -name '*.pdf' -exec sh -c '...
0
votes
2answers
44 views

Sorting folders in Unix by starting with the second character

I am trying to sort the listing of directories by starting with the second character. For example, if I do the code below, the listing of the directories are in order based on the first character. $ ...
0
votes
0answers
32 views

Redirecting the output of a program to the input file of the program (sort) [duplicate]

Given the file cab.txt $ cat cab.txt c a b When I do sort cab.txt > abc.txt I get the expected file abc.txt $ cat abc.txt a b c and the original files content is not altered. But when I do ...
-1
votes
2answers
39 views

Linux - sorting while preserving header

There have been a number of questions posed about how to sort data while preserving the header at the top. The answers I've seen don't seem to be all that general - they're not flexible enough to ...
0
votes
2answers
49 views

Perform series of commands on every value in a field

I have a tsv file. For a specific value in a column 5, I want to extract all the rows, and then cut three columns and then count the unique lines. For example for string 'abc' in column 5, I want awk ...
0
votes
0answers
18 views

How to keep directories sorted by interest or frequency of usage?

Current situation Let's say I have a cloud sync directory $CLOUD_DIR with sub-directories which I want to keep sorted by interest. In order to do that I use lexicographical order and use number to ...
0
votes
1answer
66 views

GNU coreutils `sort` behave differently

I wanted to sort a list of data and I intended to sort it based on its first column which is an IP address. 192.168.1.100 192.168.1.101 192.168.1.110 192.168.1.119 192.168.1.20 192.168.1.30 192.168.1....
-1
votes
2answers
42 views

What is the usage of V option in sort command

Having a command ls -1 | grep war | sort -V | tail -n1 to sort and list a war file name likes abc-1.4.3.12.war. What is the usage of V option with sort command?
0
votes
1answer
33 views

Sort on substring of line (not using a delimiter)

I need some help understanding how the sort command is working in the following examples: cat testfile The input data: thisfilehasduplicates thissnowhasfallen thisduckhasdied thishallwasfull ...
1
vote
0answers
26 views

How can I remove duplicate lines from 1 TB of data in a directory and all subsequent sub-directories?

I need to remove duplicate lines from about a TB or so of text files contained within a directory and various sub-directories of that directory. I've tried stuff like using sort -u *.txt > newfile....
7
votes
1answer
427 views

Sort LC_ALL=C vs LC_ALL=C.utf8

Does the linux sort command differentiate between C and C.utf-8 locale? the sort manual says to use LC_ALL=C to sort by byte value, but i saw that C.utf-8 allows also utf8 values (and not just ASCII) ...
4
votes
5answers
190 views

How can I sort a list of directories alphabetically and get the first value that sorts after a specific string?

I have a directory full of backup folders, with names in the format yyyy-MM-dd--HH:mm:ss If I enter a date in the same format, is there a way to get the first directory that sorts after it, and copy ...
0
votes
2answers
58 views

Script in Bash: Find all files

I want to write a script in Bash which finds all files less than 100b in /etc directory, splits the results on pages and saves the results to a file. I tried to use this command: find /etc -size -...
1
vote
2answers
60 views

sort special characters like + and -

I have a file consisting of several lines and columns. The columns are delimited by \t. Now I would like to sort the file based on the second column, which can be done with, e.g. sort -f -t$'\t' -k2 ...
3
votes
2answers
70 views

Sort numerical column

I'm trying to sort a file based on a particular position but that does not work, here is the data and output. ~/scratch$ cat id_researchers_2018_sample id - 884209 , researchers - 1 id - 896781 , ...
0
votes
4answers
232 views

How can I sort within an awk script on Linux?

I have file fruit that has the following content: Apples, 12 Pears, 50 Cheries, 7 Strawberries, 36 Oranges, 2 I would like to sort the numerical data of the file: for(i=1;i<=NF;i++)j+=$i;printf "...
0
votes
2answers
75 views

sort in pipe does not work

I have many of those files and I would like to know what is the highest Memory consumption (Mem) $ cat utg006012l-racon-2.fasta.o5230935 [racon::Polisher::initialize] loaded target sequences 0.013133 ...
1
vote
2answers
35 views

List sorted on 1st field, how can I join 2nd field on lines where 1st field is the same?

I have several lists with two fields - first field contain an URL, 2nd field an email-address (an account). The 2nd field is the same for all entries in a list. I concatenate the lists to one list, ...
2
votes
1answer
77 views

Remove lines with repeated first field/column from a large file

I have a very large file (snippet below). I need to remove any lines where the number in the first column does not increase consecutively from the line above. For example, I want to keep the first ...
0
votes
1answer
34 views

sort file of unix pathnames from two drives

I have a file containing pathnames from two directories. I want to sort them by filename disregarding parent directories. Text is as so: /mnt/samsung/a/b/c /mnt/samsung/d/e/f ... /mnt/wd/a/b/c /mnt/...
1
vote
1answer
36 views

Why is sort folding cases and what is the option to get case sensitivity?

I'm trying to sort a list strings case-sensitively, but the list is coming out in case-insensitive order. The man or --help info for sort gives me a -f or --ignore-case option, but doesn't list an ...
1
vote
2answers
96 views

Linux Sort Command Doesn't Include Bottom 9 and 14 Lines in Two Text Files [closed]

Hi I have a peculiar issue... when I run the Linux sort command to sort two text files, 3331 lines and 4344 lines each, only the 3317 and 4335 topmost lines are included in the output files. Here are ...
2
votes
3answers
65 views

How to sort subdir glob by filename, not full relative path

Given a tree of files like this: subdirFoo/2019-06-01-blah.ext subdirFoo/2019-06-07-blah.ext subdirFoo/2019-05-02-blah.ext subdirBar/2019-06-03-blah.ext subdirBar/2019-05-05-blah.ext subdirBar/2019-...
2
votes
1answer
21 views

sort utility with compound numeric keys

The documentation for the sort utility leads me to a different conclusion about its behavior than what is observed. Consider the below command: $ sort -k2,1n <<EOF 9 alpha 100 alpha 9 zeta 100 ...
0
votes
1answer
48 views

Sort file by row and with scientific numbers

I have a file F.tsv with 13 columns, the last column (the 13th columns) looks like this: 2.1e-06 0.58 10 8.7e-22 0.0014 0.034 9.5 0.67 0.67 0.68 9.2 8.4e-22 9.7 I've tried sort -k 13 F.tsv but it ...
1
vote
0answers
51 views

Linux whole-line sort does not sort correctly [closed]

I want to whole-line sort a file with the linux command sort. My file cat hello #_ * #1 When run with sort hello #_ * #1 Because # stands before * in asccii table, my expected result is #_ #1 * ...
-1
votes
2answers
73 views

Linux & Bash Chromosomes sorting files

I need to combine all the files with genomic data in that particular way. It means it should be sorted first by numbers then alphabetically. The names of files are: Homo_sapiens.GRCh38.dna.chromosome....
0
votes
1answer
34 views

Question regarding sort --key

I'd like to sort a file, where sorting's key is a number in the second column, starting from the 2nd character of this column. For instance: 4 31 5 a14 2 h11 1 x4 2 z3 And the desired output is: 4 ...
0
votes
2answers
42 views

Sort command changes string output

I stumbled on this anomaly regarding the sort command and I can't find an explamation to why it happens - running the following command: cat ~/.bash_history | uniq -c | sort -h -r | head Should ...
1
vote
2answers
49 views

List all files present in backup2.tar.bz2 but not present in backup1.tar.bz2

This lists all files in two backups, sorted by size: tar tvf backup1.tar.bz2 |sort -k3 -n >backup1_files.txt tar tvf backup2.tar.bz2 |sort -k3 -n >backup2_files.txt I'd like to list all files ...
1
vote
1answer
25 views

How can I extract only the lines that have a specific string AND THEN sort the numbers at the end the extracted lines , from lower to higher value

The below 3 example lines are extracted by : grep "Time to convert event = "[1-9] output.log However I need to then be able to SORT from lower to higher, the number after Time to convert event = x....
-1
votes
1answer
17 views

Need to get a single record based on latest date in the 3rd colum

I want to get a single record for each value in the first column there three records below have value of 2019-10-20 as the latest date, in this case first we get the three rows, then latest date of ...
0
votes
0answers
39 views

To shred recursively, sorting alphanumerically

I want to shred permanently and recursively, but sorting firstly numerically and then alphabetically. The command shredded in wrong order/sort, for example: shred: ./browser/tabwidget/tabwidget.cpp: ...
0
votes
3answers
123 views

Delete line if other line starts with current line (column wise)

I've got a file input.txt in the following tab delimited format: aaaa bbbb aaaa bbbb c aaaa bbbb c dd aaaa bbbb cc aaaa bbbb x aaaa bbbb xx dddd eeee dddd ...
0
votes
1answer
113 views

KEYDEF of sort man page

I have read Trying to sort on two fields, second then first. I am still confused. In the man sort page: KEYDEF is F[.C][OPTS][,F[.C][OPTS]] for start and stop position Why there are two OPTS? ...
5
votes
1answer
255 views

how to sort based on numbers on column with seperator on bash

how to sort these data by fifth column PREPAID|085319338982|Replacement Card|2016-05-31 15:15:29|218BKSAT||14121837 | 0 PREPAID|08128352315|Replacement Card|2016-05-31 15:15:33|218KKSAT||14121842 | 0 ...
1
vote
2answers
41 views

Replace single field numbers with double field numbers (1->01)

beginning with male 9 male 11 male 9 male 1 female 4 female 13 male 14 sort -u -k1,1 -k2,2n returns female 13 female 4 male 1 male 11 male 14 male 9 male 9 how can I make these numbers show as ...
0
votes
2answers
223 views

Bash - sort and uniq on array

This is a similar question to this one I want to do the word count but this time, using an array. For example, I have the following IPs inside a bash array called IPS. IPS=("1.1.1.1" "5.5.5.5" "3.3....
-1
votes
1answer
35 views

Sorting multiline expressions [duplicate]

I have a file that contains entries that are indexed by a key: \newglossaryentry{[alpha key]} { [some lines with arbitrary content] } Two entries may be separated by one or more lines. How would ...
2
votes
2answers
275 views

Is there a Linux image viewer that can browse images by a specific order?

I've accumulated hundreds of pictures and I'd like to sort them. For that purpose, more often than not, I check a list of them in Thunar, sorted by size, and then watch them with an image viewer. The ...
0
votes
2answers
47 views

Sort alphabetically into different files

I have a file which I am sorting alphabetically. That is simple: cat {some file} | sort > {newfile} But, I need to sort if alphabetically, by the 3rd column in the file, and each letter will go ...
3
votes
3answers
85 views

Sort by contiguous digits as a single number

A command outputs this: file_0 file_1 file_10 file_11 file_12 file_13 file_14 file_15 file_2 file_3 file_4 file_5 file_6 file_7 file_8 file_9 How can I use awk or some other posix tool to actually ...
0
votes
3answers
124 views

change format of uniq -c command

I want to get the unique words and its count from a file. When I run the bellow command, sort words.txt | uniq -c 2 america 4 and 1 england 1 file 1 for 1 place But I want the ...
0
votes
1answer
34 views

How to sort by numeric (logic) ascending but alphabetic order with Debian

Assume I have a list of parsed version tags like 0.2 0.1 0.10 0.9 If I use sort I get (Am I right, this is called the collation order?) 0.1 0.10 0.2 0.9 If I want the numeric (logic) order I'd ...

1
2 3 4 5
16