Tagged Questions

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

learn more… | top users | synonyms

3
votes
3answers
194 views

sort lines according to day

I have a text file in following format, and I need to sort the lines according to date. Is there some simple way to do it (preferably in bash) ? 2013-May-30 2 2013-May-21 10 2013-Jun-27 8 ...
1
vote
2answers
7k views

How to sort results from ls command by modification date (directories first)?

I can fire ls -lrt to get files and folders sorted by modification date, but this does not separate directories from files. I want ls to show me first directories by modification date and then ...
5
votes
1answer
2k views

Sorting a file based on one column using Unix and Awk

I need to sort the input file according the 6th column, which is the score. Input File: Sc2/80 20 . A T 86 Pass N=2 F=5;U=4 Sc2/80 20 . A C 80 Pass N=2 F=5;U=4 Sc2/60 55 . G T 90 Pass N=2 F=5;U=4 ...
3
votes
2answers
112 views

Ignore blank keys in coreutils sort

How do you ignore or is there a way to change the sort order of empty keys when using sort -k? # cat afile a b 11 20 93 45 55 26 09 31 How can I sort the empty column b values at the bottom so it ...
1
vote
2answers
262 views

How batch mv files to folders created and named by modification date?

I am quite new to the terminal stuff and I just couldn't find any answer on the aforementioned subject. On my OS X, I have a folder with about 4000 pics that I'd like to move into folders that are ...
1
vote
2answers
556 views

Sort lines based on a variable-width number at a fixed position

I'm trying to sort a file using the Sort command but its not working: The file contains lines like: photo1 photo11 photo12 photo13 photo17 photo18 photo19 photo2 photo22 photo23 photo25 photo26 ...
1
vote
5answers
607 views

Need some sed magic: Moving marked lines to the beginning of a file

I find myself in dire need of some sed magic (I really need to sit myself down and learn this). I have a file with lots of lines. After reviewing it, I've marked some lines by adding a star (*) to ...
2
votes
1answer
307 views

Incorrect sorting according en_US.UTF-8

I'm seeing a weird behavior of the sort command when I sort by en_US.UTF-8. I'm trying to sort this file (LC_COLLATE=en_US.UTF-8 sort testdata): 㐀 㐃㐄 ▼▽◢ ㎏㎜㎝ bqz ㄠㄨㄩ─┃┆ ...
1
vote
0answers
38 views

Characters not defined into iso14651_t1_pinyin are not sorted properly

when I try to sort characters not defined in iso14651_t1_pinyin, no sort happens, they are simply left in place. I would expect to see them sorted according to their codepoint. Is there a way I can ...
3
votes
1answer
692 views

Can I unzip and merge sorted text files in a single operation?

I have tens of thousands of gzipped text files, each of which has already been sorted internally. I've written a script to unzip them (creating a copy) and then using sort -m to merge them. It all ...
0
votes
1answer
5k views

How to sort by multiple columns? [duplicate]

I have a tab-separated file, and I want to sort it by its columns 9, 14, and 16. By this I mean that all rows that agree at column 9 should be sorted by column 14, and among these, those that also ...
0
votes
1answer
201 views

How to sort date: YYYY.MM.DD. HH:MM?

INPUT: b|2013.06.03. 18:47| a|2013.06.03. 13:15| c|2013.06.03. 13:53| needed OUTPUT: a|2013.06.03. 13:15| c|2013.06.03. 13:53| b|2013.06.03. 18:47| How can I sort the dates correctly in ...
3
votes
1answer
120 views

Sort only on the second column [duplicate]

I'm trying to sort a file where typically (not always) the lines are whatever:[A-Ba-b0-9_]: values where fields are separated with :. Some lines do not follow this pattern, I'm not interested in ...
4
votes
2answers
514 views

Sort files by modification time

I've seen many questions and answers here using a construction along the lines of list_dir=`ls -t /path/to/dir/` for i in $list_dir; do or ls -t | while read i; do Now, I know that you shouldn't ...
4
votes
4answers
177 views

how to sort access log efficiently in blocks

Access logs are more or less sorted by time, but to aggregate connections by time (uniq -c), you need to sort them a bit more. For a huge access log sort is very inefficient, because it buffers and ...
23
votes
4answers
11k views

What is the difference between “sort -u” and “sort | uniq”?

Everywhere I see someone needing to get a sorted, unique list, they always pipe to sort | uniq. I've never seen any examples where someone uses sort -u instead. Why not? What's the difference, and why ...
3
votes
2answers
244 views

How to use output of one command as input in another command

I made a copy of all the backups made on Wed of every week The time stamp of each file is not sorted but the day is Wednesday of every file Now, I need to sort each file based on time Stamp e.g if ...
4
votes
3answers
563 views

Sort using custom pattern

Is there a way to output file's contents using custom patterns? For instance, having a file myfile with following contents: a d b c ..how would one sort it using following pattern: print lines ...
4
votes
2answers
327 views

sort part of a file

How can I sort the file by the second column from the terminal. The content of the file is: Nome Note ------------ Mehdi 0 Sunday 20 Others 10 Shnou 5 Using sort -t' ' -nk2 is not ...
3
votes
2answers
1k views

Specify the sort order with LC_COLLATE so lowercase is before uppercase

Given the file: $ cat file 1 a C B 2 c 3 A b By default sort will: $ sort file 1 2 3 a A b B c C With LC_COLLATE=C so will sort in uppercase letter before lowercase: $ LC_COLLATE=C sort file 1 ...
2
votes
6answers
1k views

sort ls output by users

On Linux, is there a way to sort ls output by users? What I try to achieve is something like this: user_a   file1 user_a   file2 user_b   another_file user_c   this_file user_c ...
1
vote
2answers
246 views

How to remove duplicate entries from a file?

I have a comma-separated list of domain-names in a file; unfortunately there are duplicate entries for some domain-names. Is there a way to find and remove the duplicate entries from the file? The ...
0
votes
3answers
474 views

Sorting IP address according to the second field in file

in my ksh script I need to add the following task ( OS - linux/solaris ) I have the following file more test.txt /etc/backup/app 172.1.120 172.110.120 /etc/backup/app 172.1.120.12 ...
1
vote
3answers
266 views

another question with sort in bash [duplicate]

How can I ignore the space in "Kuala Lumpur" when sorting this list? I cheated it by tabbing the columns and sorted on the tab which gives me the right results but I would like to know how to deal ...
1
vote
3answers
1k views

Sort with unequal whitespace in first column

I need to sort this list by name, high temp and low temp: Kuala Lumpur 78 56 Seoul 85 66 Karachi 95 75 Tokyo 85 60 Lahore 85 75 Manila 90 85 I figured since whitespace is the delimiter for a column ...
5
votes
2answers
522 views

Unix sort out of memory

I'm sorting a 25 GB file containing 200M lines on Fedora 18 using: sort -S 10G -T /bigdisk bigfile and I am getting process killed due to no memory. The process isn't maxing out my RAM before death ...
2
votes
2answers
436 views

Sort lines by unicode value

I'm trying to sort a text file linewise by their Unicode values. As far as I can tell, this means numerals first, then letters, then CJK-Ideographs. However, sort (with LC_ALL=C) fails horribly at ...
2
votes
0answers
35 views

Unexpected ordering of strings in `sort` command [duplicate]

I'm trying to sort a text file using certain columns in the file as a sort key. Since the file doesn't have separators and fields sometimes stick to each other, I have to convert spaces to some ...
1
vote
1answer
89 views

Sort aligned columns

I have a program which output looks like this # Status VAL1 VAL2 Description 1 some text 2.5 4.4 Some long other text 5 some text 2 14.5 2.0 Some long other ...
2
votes
2answers
211 views

Select greatest numbered filename

Simple requirement but can't find anything online which can achieve it. I have a list of dated files as below... filename_20120101.dat filename_20120102.dat filename_20120103.dat I ...
1
vote
3answers
472 views

Reading a directory in shell script

I want to read a numbered directory which is under a path, into a variable in shell script. The paths are something like this: .../releases/R1/... .../releases/R2/... .../releases/R3/... Each time ...
3
votes
2answers
181 views

Delete duplicate images. Need Software for computing average color of an image

I want to delete duplicates in a massive bunch of images. Well as I have dups of the same picture in a different resolution I will make the deletion myself. BUT I want to do this in linear time. So I ...
1
vote
1answer
1k views

How to match 2 large file and print the difference in shell script

I have 2 files. File1 has 400k numerical records. e.g: 1 2 3 4 5 6 .. and so on File 2 also has 420k numerical records. e.g: 1 2 3 4 6 .. and so on Both these file are in unsorted manner. I want ...
22
votes
1answer
398 views

Why is sort changing the order of lines with identical sort keys?

Here is the data: D 2 B 2 A 2 When I run this command: sort -k2,2 file it outputs: A 2 B 2 D 2 My question is that when I specify only the second column -k2,2, why is it that it sorts by the ...
1
vote
1answer
923 views

Sorting by one column then the

Say i have a output file with following: 010513 08:04 ROUTER1 192.168.1.1 68.130.5.10 HIT(1) 010513 08:04 ROUTER1 172.168.1.1 28.130.5.10 HIT(1) 010513 08:04 ROUTER1 122.168.1.1 ...
0
votes
1answer
256 views

How does -k flag work in sort command? [duplicate]

I have got a dataset like this: manufacturer,model,year,mileage,price plym fury 1970 73 2500 chevy malibu 1999 60 3000 ford mustang 1965 45 10000 volvo s80 1998 102 9850 ford thundbd 2003 15 10500 ...
4
votes
1answer
292 views

Why is uniq ignoring Unicode and lines with a single letter?

I'm trying to combine both the American and British dictionaries into one large dictionaries, and I'm trying to remove all the duplicates from the superset, but it seems that uniq is not outputting ...
3
votes
1answer
551 views

Sort command not working as expected

I have got a dataset like this tack2@domain.com,2009-11-27 overflow@domain2.com,2009-11-27 overflow@domain2.com,2009-11-27 When I am running command to delete all of the same entries of column2 ...
3
votes
2answers
380 views

sort a file based on length of the column/row

I need to sort a file based on the number of chars in the first column. I have no idea on how to go about this. (On Linux, so sed/awk/sort is available). An example: .abs is bla bla 12 .abc is bla ...
1
vote
2answers
207 views

`echo -e 'Q\ns\nV' | sort` doesn't sort

Why do : $ echo -e 'Q\ns\nV' | sort outputs Q s V without changing the order of my list (taking in account the lower/uppercase ?)
2
votes
2answers
463 views

Reorder folders on FAT32 drive

My car can read MP3 files from a FAT32 flash drive. I have a folder for each artist on the drive, then MP3 files in those folders. However the car does not read the folders alphabetically, but by the ...
0
votes
1answer
114 views

Remove repeated words with suffix in a file

I have a list of records in a file as in below example word_word1 word_word1_acc word_word2_acc word_word3_acc word_word4 I need to remove only word_word1_acc line in the file as it is only a ...
1
vote
2answers
455 views

Deleting specific lines and duplicates from a 11gb wordlist text file

I have an 11gb wordlist file which is already sorted as each word is on its own line. I need to remove duplicates and lines starting from 077. I guess I need to run sed and sort -u together but I ...
2
votes
1answer
835 views

How can I list my `at` jobs by date?

I am using atq command, but I need to list my at jobs by date. How is that possible ?
1
vote
3answers
2k views

strange problem: join: file 2 is not in sorted order

sort flash_int_list.txt|join finish_comm - > t1 join: file 2 is not in sorted order I have sorted flahs_int_list.txt but it still says file 2 is not in sorted order what is wrong ? the ...
5
votes
1answer
1k views

comm: file is not in sorted order

I used comm to compare two sorted files. Each line in these files are positive integer numbers. But the results show comm: file 1 is not in sorted order comm: file 2 is not in sorted order How ...
5
votes
1answer
191 views

Alphabetizing names in `ls` alias with .files not intermingled

I am currently using the following ls alias: alias ls='ls -alhGkpsq --color=auto'. This results in following directory listing. [03:35] bryson@brys ~ :$ ls total 48K 4.0K drwx------ 4 bryson 4.0K ...
13
votes
2answers
10k views

Trying to sort on two fields, second then first

I am trying to sort on multiple columns. The results are not as expected. Here's my data (people.txt): Simon Strange 62 Pete Brown 37 Mark Brown 46 Stefan Heinz 52 Tony Bedford 50 John Strange 51 ...
3
votes
1answer
4k views

The simplest method to count lines matching specific patterns, including '0' if line is not found?

I have very big logs (several gigabytes per day), that can (but do not need to) contain specific lines. I have to count the number of occurences of every one of these lines on a daily basis. I have a ...
1
vote
3answers
186 views

How to sort and join at the same time?

I have 2 files, one having 2 columns, another having 1 column. The second file is sorted using sort -u. Now the task is I need to join this column with the first column of the first file, which is not ...