Questions tagged [sort]

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

Filter by
Sorted by
Tagged with
0
votes
5answers
72 views

Can a shell script find all groups of consecutive lines matching the same regex and shuffle them?

I'm writing quizzes for my students in a markdown language. One of the quizzes might look like this: % QUESTION Who played drums for The Beatles? (X) Ringo ( ) John ( ) Paul ( ) George % QUESTION ...
1
vote
1answer
17 views

Merge sort and extract new uniques?

I found a post that answers how to merge sort and remove duplicates. I'm interested in expanding on this and extracting new unique entries from the post-merged file. What would be the command to do so?...
-1
votes
0answers
29 views

How does -c option affect the sort command?

I have trouble understanding the difference between -c and -C when using sort. Specifically I want to know how it affect -u
0
votes
2answers
45 views

CAT FILE with sort lines by DATE column

I have a text file that contains the log info about the webserver. DATE Format: Day-Month-Year Sample content: /tmp/archive/9-10-2020/error_04.log.gz /tmp/archive/9-10-2020/error_05.log.gz /tmp/...
5
votes
2answers
156 views

Print count number of unique pattern occurences after each occurence

Supposing I have a log file containing thrown Exceptions: ExceptionA loggedFunctionCall ExceptionB ExceptionA loggedFunctionCall ExceptionD ExceptionB loggedFunctionCall ExceptionB I want to count ...
6
votes
4answers
670 views

How to remove unique strings from a textfile?

Sorry guys I had to edit my example, because I didn't express my query properly. Let's say I have the .txt file: Happy sad Happy sad Happy sad Sad happy Happy sad Happy sad Mad sad Mad happy Mad happy ...
2
votes
1answer
86 views

How to list files - sorted by both filename and modified date?

I have some files with their names starting with 00, 01, ..., but there can be multiple filename with the same number i.e. 00_filename1, 00_filename2. I want to list them sorted by their names, but if ...
0
votes
0answers
28 views

How to debug a hanging sort -u job?

I have a 32GB text file I am trying to remove duplicate lines and sort using sort -u mybigfile.txt. The job hangs forever so I ended up splitting it into 10 files and one of those 10 files wont finish ...
1
vote
1answer
23 views

How to pipe output of command to two separate commands and store outputs

I have a really long command that runs over a huge file and I am forced to run it twice which doubles the time it takes to run. This is what I am doing at the moment: x=$(command | sort -u) y=$(...
1
vote
1answer
15 views

mac: sorting data by column

I have a long csv file containing 2 columns in the following format RG_cne_1| 0.316571 RG_cne_10| 0.26924 RG_cne_100| 0.227538 RG_cne_1000| 0.385216 RG_cne_1001| 0.247508 RG_cne_1002| 0.496622 ...
0
votes
1answer
40 views

Loop over files in different directories

I have a set of text files containing values and stored across several directories. I need to workout a command with loop, so that I can apply my command to each files in several directories. The code ...
0
votes
3answers
33 views

Sort while neglecting regex pattern

I want to sort a list of url (1 url/line) in a file, such that if the url begins with www. or m., the sort is done assuming that, that part doesn't exists (or is irrelevant for sorting). Any ...
0
votes
2answers
68 views

Unique row values skip the header in csv [closed]

I'm trying to find all the unique values in a column. However, with this command I'll also get the header row. How do I skip that? awk -vFPAT='([^,]*)|("[^"]+")|","' '{if ($2!~...
0
votes
2answers
97 views

awk: find the oldest and newest files by date

I'm using an awk script to print the oldest and newest files created based on the date (the 6th 7th and 8th field). my sample list, date in the format (YYYY/MM/DD): file was created 2020/10/10 20:18:...
0
votes
2answers
37 views

shell: processing of multi column file

column file in the following format and I am using macOS: ./tmp/7000_CNE_lig752_cl_0.5| -10.1000| 58 ./tmp/7000_CNE_lig1029_cl_0.5| -8.0200| 40 ./tmp/7000_CNE_lig183_cl_0.5| -8.0400| 32 ./tmp/...
5
votes
5answers
432 views

How to sort a first file (csv) based on the second file keys

I am trying to find a solution where I can sort my first file using the first column based on the second file keys First file example (file1.csv) COLUMN1 COlUMN2 apple fruit dog animal cat animal cow ...
3
votes
3answers
91 views

Sorting by date with format dd-Mmm-yyyy from specific file

So I am having the following file: Certificate Name,Expiry Date,Type,Certificate file path CN=server10.de.go.com:app, 16-Jan-2021, physical, /path/to/file/ CN=sv999-c.int.de.aaas.internet....
2
votes
6answers
615 views

How to ignore letters using sort for numbers

How can I make sort or awk ignore letters while sorting using numbers in specific field? I have the following data in my text file: name name space 2018 name2 name2 space (active 2020) name1 name1 ...
0
votes
2answers
39 views

How do I find the duplicate lines in a file, output them with the filename, and do this for an entire directory?

I have few files under directory and need to find duplicate lines in each file and display the file name to identify which file has duplicate. I tried: for i in *.*;do sort $i | uniq -d ; done It ...
-1
votes
1answer
31 views

sort - prepend each group that start with the same letter in sorted list with an arbitrary string

Given the following list (input): apple banana blueberry mango melon I want the following output: == A == apple == B == banana blueberry == M == mango melon Is this possible to do in a shell ...
0
votes
0answers
30 views

sort command ignore leading blanks and enable dictionary order by default [duplicate]

1. How come sort command ignore leading blanks even though I didn't specify -b? Text File file1 Morpheus Trinity Neo Cypher Command > sort file1 Shell Output Cypher Morpheus Neo ...
0
votes
2answers
28 views

Sort by the first column only

Why sort changes second and third line when it should do nothing in below input file for given options? $ cat test1 1 4 2 5 2 1 3 6 $ sort -n -k 1,1 test1 1 4 2 1 2 5 3 6
-1
votes
2answers
123 views

why sorting du -h not working as expected?

I'm trying to sort the output of du command with human-readable flag and I'm getting the results sort only by the numeric value ignoring the extension(i.e G, M, K ...), while when removing the -h flag ...
3
votes
3answers
35 views

Sort -u (or sort | uniq) on a couple of columns but retain the info in a third column, and append it to the retained row?

I'm trying to take a table like this: a b hello a b goodbye g g test a c I say to collapse the table down to one row per unique entry on column 1 and 2, but without ...
1
vote
1answer
223 views

sort multiple files and merge

I want to sort several text files in reverse order and then merge/cat to one single text file. a.txt 0 33.1 2 33.0 10 21.1 20 21.8 b.txt 0 30.1 2 33.0 10 28.1 20 27.8 and so on *.txt ...
15
votes
2answers
1k views

How to sort this output 1,10,11..2

Sometimes I need to add more disk to a database; for that, I need to list the disks to see what disks already exist. The problem is that the output is always sorted as 1,10,11,12...2,20,21...3 etc. ...
0
votes
1answer
21 views

Sort all files by numeric name and save

There is a lot of questions about sorting files by numeric, but non of them shows how to save the change. I have a directory containes 4 files - 0.txt,1.txt,3.txt,2.txt and I want to sort the ...
1
vote
1answer
78 views

What does 'ls | sort file.txt' do?

I am just learning about shell commands; more specifically, I am learning about pipe. Right now I cannot tell the difference between the following commands: ls | sort file.txt and sort file.txt. ...
2
votes
1answer
39 views

Sort with custom pattern?

Rather than sorting based on a-z, is it possible to sort based on occurrence? Example of desired task, Input = Example Example Hello Hello Input Input List List World World ... Desired output = ...
2
votes
1answer
32 views

Implementing Sort URLs Regex Using Unix Commands

I am a newbie to regular expressions as they manifest in things such as sed, awk, sort, grep and other Unix binaries. I know that if I sort a list of URLs in my text editor (BBEdit) using this regular ...
4
votes
1answer
116 views

Joining two sorted files gives error: join: <file>:112855: is not sorted:

I would like to merge a variable from one file to another in linux. The first variable contains the name I want to merge files on. I have sorted both files using both -f and -k: sort -f -k 1,1 SCZ.N....
3
votes
2answers
219 views

Sort an output by year month and date

I want to sort the output below by year, month and date. I tried a few combinations that don't seem to be working. In the below output 2nd column is the date, 3rd is the month and 4th is the year. I ...
1
vote
1answer
35 views

combine ls -alt with readlink

I have a directory containing a lot of symbolic links and some huge subdirectories. I want to get a detailed listing, sorted by time, of just the files in the parent directory, but with targets ...
0
votes
1answer
49 views

Sort bash output by a number extracted from a specific column

I am new to bash and I am struggling with the following task: The output from UGE looks like this: mgenkin@bamdev2:~/projects/BrainFlowUtilities/BrainFlowSimulations$ qstat job-ID prior name ...
-1
votes
1answer
46 views

How to remove first word if starts with 2020- from a text file

I have a large log (text file) and want to sort it. Most lines start with a timestamp and end with a ] I don't the timestamp as part of the sort process so I thought I'd first delete all timestamps ...
1
vote
1answer
54 views

How do ls file names in numerical order that have space characters in the filename

Hi I have the following files, whose names contain spaces, on a Linux machine. I need to ls them in numerical order myfile_2020-Jul-06 00-00-00_1.csv myfile_2020-Jul-06 00-00-00_2.csv myfile_2020-Jul-...
0
votes
1answer
28 views

Sorting file based on “file” output into folders

I am having millions of files without extension and I want to sort them into various folders. I am able to identify the files by "file" but then I end with lot of different types which I can ...
-2
votes
1answer
16 views

To count the number of occurrences of first field in text file [closed]

i require to count the number of occurrences of first field in txt file and to print output file as two column file having first field of input file & no. of occurrences of fist field in input ...
0
votes
1answer
51 views

sort imput files in pdfbeads

I'm trying to make a pdf from hundreds of .tif images with pdfbeads. I can't make the program use the images in the correct numerical order. For example, during the process I see: Prepared data for ...
1
vote
2answers
36 views

How to print lines from file a file in a way of sequence i.e. sorted on basis of a specific column inside tcl script?

I want to print the file content based on sorting the 3rd column of sourcefile. sourcefile.txt: Manav Kumaom Fre shailesh himadri aif manisha Kailash mac Ravi Jwala blu Prakash Ojha Zan Mahi Aulakh ...
2
votes
2answers
159 views

How can I sort sections of file alphabetically?

I have a file of several sections, each section start with specific title but all of them ending with the same string, I want to sort the file sections according to the titles without sorting the ...
0
votes
1answer
28 views

How can i get the following output using linux sorting?

Input: C_ABC_066.T02 C_BC_066.T02 C_ABC_066.T01 C_BC_066.T01 Desired output after Linux sort C_BC_066.T01 C_ABC_066.T01 C_BC_066.T02 C_ABC_066.T02
0
votes
1answer
29 views

How to use a series of commands on vim

Hi guys in the terminal I use the command cat file.txt | sort | uniq -c . First I would like to use that command on vim and save the output to another file without the output being print when I run ...
-1
votes
1answer
35 views

Unix separation of specific numbers from Column [closed]

How can I separate specific numbers from a column and add it to a new file? For example, take all numbers that are "134" from column 3, I tried using awk '$3 == 134" file.txt but it didn't work, ...
0
votes
0answers
62 views

Permission denied when sorting in-place and overwriting

I am trying to sort the following file in-place and overwrite the original file using sort -o command, but seems the sortation is not successful. It is totally fine when I save the sorted result into ...
-2
votes
1answer
46 views

linux sorting of lists using the last parts using sort command [duplicate]

how do I sort lists like the one below using sort or any related commands? 12.ale.panal.sel.blr.teta.hf.ew.rr.lwq.ors.2018 34.ev.we.ars.lmn.2017 5.lam.bere.meto.belagn.hede.we.e.2020 54.arad.met.kal....
0
votes
1answer
35 views

sort seems to crash without indication

Correct me if I'm wrong, but I think this applies more to Unix generally than to Apache Jena or to the Windows Subsystem for Linux - after all, it's the sort utility that seems to vanish without a log....
14
votes
8answers
2k views

How can I find the most frequent word in a .csv file, ignoring duplicates on each line?

I need to find the 10 most frequent words in a .csv file. The file is structured so that each line contains comma-separated words. If the same word is repeated more than once in the same line, it ...
-1
votes
1answer
48 views

How to sort data on partial column?

I have data in a text file which I am trying to sort. I want to sort the data on the number at position 2 of the 1st column to the end on the first column. For example: Record Age Price A7859 ...
4
votes
1answer
43 views

How to sort a column that also has color data?

I have a log file and I'm looking to sort according to response time, 4th field: GET /api/user/john 200 0.194 ms - 7307 But it contains color tags, here's the output from vi: ^[[0mGET /api/user/...

1
2 3 4 5
17