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

learn more… | top users | synonyms

2
votes
2answers
439 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 ...
2
votes
2answers
2k views

Sort by regular expressions

I've got a set of POSIX regular expressions* ^BEGIN:VCARD\r$ ^VERSION[^A-Z] ^FN[^A-Z] ^N[^A-Z] ^NICKNAME[^A-Z] ^EMAIL[^A-Z] ^X-\([A-Z-]*\) ^TEL[^A-Z] ^ADR[^A-Z] ^ORG[^A-Z] ^TITLE[^A-Z] ^BDAY[^A-Z] ...
2
votes
2answers
4k views

Issues of using sort and comm

I was trying to find the intersection of two plain data files, and found from a previous post that it can be done through comm -12 <(sort test1.list) < (sort test2.list) It seems to me that ...
2
votes
2answers
234 views

Move one file at a time based from specific number in the files

Based from this question, The HTML files date format has been changed. All of the HTML files have the date such like below: 20110730dateishere dateishere is intentionally added by me in the files, ...
2
votes
1answer
50 views

sort -u (unique) works for multi-keys but not for a single key

Using GNU sort. I want to print only the first of a group of lines, based on duplicate key(s). -k1,2 works as expected – only the 1st sorted line is output printf %s\\n 'a a c' 'a a b' 'a a a' | ...
2
votes
1answer
132 views

counting occurrences of a string

I have a large database of this format: 0500506 gi|561108321|ref|NC_018143.2| 71446 0 0500506 gi|561108321|ref|NC_018143.2| 71447 0 0500508 gi|561108321|ref|NC_018143.2| 71449 0 0500509 ...
2
votes
2answers
86 views

order for listing files

If I have a list of files under a directory ullman-000.pbm ullman-001.pbm ... ullman-098.pbm ullman-099.pbm ullman-1000.pbm ullman-1001.pbm ullman-1002.pbm ullman-1003.pbm ullman-1004.pbm ...
2
votes
3answers
34 views

Move line from output to the front of output or custom reordering

I have a command find "$PWD" -name __openerp__.py|awk -F/ -vOFS=/ 'NF-=2'|sort -u and I want to take a certain line containing /web/addons and push it to the front of output then do the same with ...
2
votes
2answers
108 views

When do `sort -k 2,3b` and `sort -k 2,3` differ?

The POSIX description of the -b flag for the sort command is Ignore leading characters when determining the starting and ending positions of a restricted sort key. I can understand the use for ...
2
votes
1answer
2k 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 ?
2
votes
1answer
313 views

Numeric sort by the column values

For example I have some test file and want to sort it by the column values. After awk -F'[:,]' '{print $16}' test.json I get next output for the column 16: 123 457 68 11 939 11 345 9 199 ...
2
votes
3answers
172 views

Get the last minute dated lines from list

If I have an input file with a list of users and their dates they were last signed in, how can I select with a sort | awk function the last minute lines? The dates are written in a +%H:%M:%S format. ...
2
votes
2answers
187 views

Check if a drive has been Zeroed with xxd and uniq?

I'm looking for a way to check if the entire binary contents of a USB device are purely 0s. I'm trying this command: sudo xxd /dev/sdb | uniq but it has no output and just runs forever. I've ...
2
votes
3answers
659 views

How can I get the last line number of unique commands when grepping my history file?

I rely on my history file for previous commands, especially ones that are long with many parameters. Once I find the command and its line number(nn) I use !nn to run it. I prefer to see the full ...
2
votes
1answer
515 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 ㄠㄨㄩ─┃┆ ...
2
votes
1answer
77 views

How sort command column option is handled

I have a file like 1.2.3.4 1.1.1.1 4.5.6.7 1.1.3.5 When I gave sort -t. -k3 inp3 1.1.1.1 1.2.3.4 1.1.3.5 4.5.6.7 and when I gave sort -t. -k3,3 inp3 1.1.1.1 1.1.3.5 1.2.3.4 4.5.6.7 second ...
2
votes
1answer
64 views

Sorting image files based on whether the content is picture or graphics: updating an older solution?

Someone wanted to sort files in a directory according to whether the files are pictures(camera) vs. design graphics. On Stackoverflow, there is an older solution/proof-of-concept involving the ...
2
votes
2answers
476 views

Calculate median value for a column and say if this value is “OK” or “ERROR” if falls within acceptable range

I would like to calculate the median value of a particular column in a .txt file, output that value and also say if that output value is ok. I can do the initial steps and output the median value, ...
2
votes
4answers
216 views

How do i Reverse output already piped from sort and cut commands

I have to take user input of there UID then use it to reference the /etc/passwd directory and sort the data by first name and display only username,firstname,lastname in that order. The problem i'm ...
2
votes
1answer
161 views

How to use gnu sort to sort lines with field delimiter present only on some lines

In my .vimrc I list my vundle bundles like so: cat ~/.vimrc ... Bundle 'Raimondi/delimitMate' Bundle 'kien/ctrlp.vim' Bundle 'matchit.zip' Bundle 'upAndDown' Bundle 'rking/ag.vim' ... Now, I would ...
2
votes
2answers
798 views

Creating recursively sorted RAR archive

For various reasons I decided to use RAR archive to store some data, instead compressed tar. Happy with decision, except for one thing: I can't find a way to store files sorted. Order of files is ...
2
votes
2answers
78 views

Sort files with a specific extension by modified time and store them into an array

I have found many answers to sort the files of directory and even to save them in an array. Sorting Example ls -t Directory listing in array array=(*) My particular problem needs to sort files ...
2
votes
0answers
105 views

Installed coreutils on CentOS for sort --human-readable flag but it still doesn't work

I'm trying to do du -h | sort -h, but my CentOS 5.7 doesn't have -h flag for sort. So I installed coreutils Updated: coreutils.x86_64 0:5.97-34.el5_8.1 Complete! yet sort still doesn't have ...
2
votes
0answers
39 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
2answers
199 views

How to sort a file by a column which is a mix of numeric, alphabet and punctuation characters?

I have a text file which is of the form - b SN:2 d SN:5 f SN:10 g SN:11 h SN:15 i SA:3 j SN:1 k SN:4 And I want to sort by the second column, actually the numerical value in the ...
1
vote
3answers
147 views

lines with unique checksum

I have a file A of lines of equal length n. I have a program that for each line in A can output a line of length n which its key. The program can either write the sequence of keys for the lines in A ...
1
vote
2answers
437 views

how to sort files by their permissions using ls?

I have a large number of files and directories in one directory. I need to sort them in terms of the permissions. For example drwx------ drwxr-xr-x drwxr-x--- I am just wondering if we can sort ...
1
vote
2answers
161 views

Sort files into directories named by prefix of file

I have a bunch of files like this 5830_1.png 5830_2.png 5830_3.png 5831_1.png 5832_1.png 5832_2.png I'd like to sort these files all into directories that take the prefix of the file name as the ...
1
vote
2answers
258 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 ?)
1
vote
2answers
112 views

sort only the first column and uniq

I have a list as such below: 1,cat 1,dog 2,apple 3,human I'd like an output like this: 1,cat,dog 2,apple 3,human So value 1 from column 1 contains the value of cat and dog from ...
1
vote
2answers
410 views

How do I move a line in a text file up or down by one line?

I have some text files, and I'd like to be able to move an arbitrary line in any of the files up or down one line (lines at the beginning or end of the file would stay where they are). I have some ...
1
vote
5answers
170 views

How to get the unique count of a particular part of a string

I have a set of data in a file. psf7433-nlhrms unit7433-nobody unit7333-opera bpx7333-operations app7333-osm unit7330-partners psf7331-pdesmond unit7333-projm mnp7330-redirect unit7333-retailbanking ...
1
vote
3answers
2k 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 ...
1
vote
3answers
69 views

Display distinct values of a list and number of occurences

I have a program that writes on the standard output a list of string values, one per line, and I would like to display in real time the list of distinct values along with the number of occurences for ...
1
vote
2answers
1k views

Sorting a csv file [duplicate]

I need to sort a CSV file, but the the header row (1st row) keeps getting sorted. This is what I'm using: cat data1.csv | sort -t"|" -k 1 -o data1.csv Here's a sample line: ...
1
vote
1answer
309 views

Sort in Linux for column, keeping other values intact

NODE_154_length 847 2997 NODE_154_length 3283 4509 NODE_154_length 4672 5715 NODE_154_length 6977 7768 NODE_29_length 3790 4317 NODE_29_length 4356 4712 NODE_29_length 4356 4712 ...
1
vote
2answers
1k 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
4answers
86 views

Sort command on more than one field

I have a file with contents 192.168.1.3 192.168.1.4 192.168.1.2 10.1.1.1 10.1.1.2 10.1.1.3 192.168.1.56 192.168.1.43 10.1.1.23 When I gave $ sort -h -t. -k3,4 sort_test.txt 10.1.1.1 10.1.1.2 ...
1
vote
3answers
411 views

How to tar files with a sorted order?

If you tar a directory recursively, it just uses the order from the os's readdir. But in some cases its nice to tar the files sorted. Whats a good way to tar a directory sorted alphabetically? ...
1
vote
1answer
6k views

Sorting file by second column

How can I manipulate a two columns tab-separated text file by sorting by the first element of the second column (only if the first column element is the same)? Exemple: Input File 1 A 1-2 A ...
1
vote
3answers
80 views

How can i get the process with the biggest pid?

How can I get the process with the biggest pid using ps?
1
vote
2answers
362 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
365 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 ...
1
vote
3answers
225 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 ...
1
vote
1answer
362 views

Sort -u Function Command Not Working

As you can see in the picture attached screen shot After I used the sort command to sort a VERY large wordlist file I then split them up using the Split command. From there I confirmed that the ...
1
vote
2answers
65 views

How do I transform array output sorted in lexicographic order to numeric order

I have a text file that consists of data in this form: int array[0] int array[1001] int array[1002] int array[1003] int array[2] int array[2001] int array[2002] ... In other words, the numbers ...
1
vote
5answers
111 views

How to sort on two fields of numbers

I have a list of filename like so: epdb_0_0.pdb epdb_0_10.pdb epdb_0_11.pdb epdb_0_12.pdb epdb_0_13.pdb epdb_0_14.pdb epdb_0_15.pdb epdb_0_16.pdb epdb_0_17.pdb epdb_0_18.pdb epdb_0_19.pdb ...
1
vote
1answer
55 views

List the lines with the highest scores

I have the following problem concerning the sorting of a content of a file. I have a file called points.txt and it contains the following table of data: Jim:4 Tim:8 Lin:6 Tom:1 Esko:2 Jaska:5 Erkki:7 ...
1
vote
3answers
612 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 ...
1
vote
3answers
380 views

Numerically sorting files [duplicate]

Possible Duplicate: List files sorted numerically How can I sort this according to the number of last field? I tried with sort -t ' ' -k9,10n: -rw-r--r-- 1 root root 440 May 14 08:52 ...