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

learn more… | top users | synonyms

1
vote
1answer
45 views

sort and uniq in awk

I know there are "sort" and "uniq" out there, however, today's question is about how to utilise AWK to do that kind of a job. Say if I have a list of anything really (ips, names, or numbers) and I ...
1
vote
2answers
53 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 ...
2
votes
3answers
94 views

Sorting numbers and respective units in columns

I have a list like this: 1,kg,cat 1000,g,dog 20,g,apple And I want to sort it by weight. 1 kg and 1000 g would be the same, so I'd like to have my rows sorted by weight. My data set is ...
0
votes
1answer
49 views

can we get sorted grep output

I have same: 1.txt with apple written in it, 2.txt with mango written in it, 3.txt with apple written in it, 4.txt with mango written in it. grep -e apple -e mango *.txt will give result as: 1.txt: ...
4
votes
1answer
21 views

Sort based on field1, field2 but preserving field 1 sort and ignoring nulls/blanks in 2nd sort

After doing a lot of home work and running multiple test scenarios, I decided to get help from experts Here is my scenario Input data after sorting by Column 1 -bash-3.2$ sort -t'|' -k1 -k2 ...
4
votes
3answers
125 views

sum columns based on matching fields

I have encountered a problem that exceeds my basic unix knowledge and would really appreciate some help. I have a large file in the following format: 2 1019 0 12 2 1019 3 0 2 1021 0 2 ...
1
vote
3answers
133 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
1answer
30 views

Combining, sorting and deleting duplicates in numerous gzip files

I am going to be combining 15 different gzip files. Ranging in size from 2 gigs to 15 gigs each so the files are relatively large. I have done research on the best way to do it but still have some ...
1
vote
2answers
108 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 ...
3
votes
5answers
114 views

Sorting bigger files gives segmentation fault

mkdir tmp sort -u *.txt -T tmp/ -o output.txt there are just a few few ten GByte sized files that needs to be sorted.. The problem is that after a few minutes sort gives a segmentation fault. The ...
3
votes
1answer
49 views

How to sort an associative array and retain the keys?

I have an array with filenames as keys and a numerical value as values. MYARRAY[00001.jpg] = 31 MYARRAY[00002.jpg] = 200 MYARRAY[00003.jpg] = 98 I need to sort them so they are ordered by value. ...
-1
votes
1answer
26 views

How to sort by column and break ties randomly

I have a tab-delimited file with three columns like this: joe W 4 bob A 1 ana F 1 roy J 3 sam S 0 don R 2 tim L 0 cyb M 0 I want to sort this file by decreasing values in the third column, but to ...
1
vote
2answers
32 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
4answers
79 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
1answer
51 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
51 views

Unix sort by multiple columns

I have trouble understanding unix sort. Consider the following file (tab separated) aa ~ a1 aa B b A b ~ e bb B bb ~ B When calling: cat tmp2 | sort -t $'\t' -k1,2 I get aa ~ a1 aa B ...
4
votes
5answers
272 views

sort order explanation

Giving a lot of files, sort -n gives me this result: f1.txt f10.txt f2.txt which doesn't seem right to me. What is the explanation? Can I get this by default: f1.txt f2.txt f10.txt
1
vote
3answers
54 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 ...
2
votes
1answer
73 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 ...
1
vote
3answers
197 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
79 views

How can I list hidden directories, then directories, then hidden files and finally files with ls?

I'm trying to figure out how to list the contents of a directory in the following group order: Hidden directories Non-hidden directories All other hidden files (including regular files, symlinks, ...
2
votes
0answers
59 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 ...
3
votes
2answers
46 views

Trying to sort on two fields first is second criteria

I'm trying to sort on multiple columns a file with GNU sort. The format of the source file tmp/file.txt is : 03A12345679 2014-09-30-00.00.01.00 "03" => first column "A" => field separator ...
3
votes
2answers
211 views

Sorting the output of `ps`

I am trying to understand why ps does not behave the way I expect it to. From the man pages, the following command should display ppid and lstart, with items sorted by lstart order. However when I run ...
2
votes
1answer
311 views

Cut and Paste Commands

So I have: $ cat fruits 2 bananas 3 cherries 4 figs 5 dates 6 elderberries 7 apples 8 grapes and 1 $ cat prices 2 2.18 3 4.11 4 1.69 5 4.52 6 1.73 7 1.01 8 1.09 Every line from 'fruits' ...
1
vote
5answers
131 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 ...
2
votes
2answers
81 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 ...
1
vote
1answer
69 views

Sort and backup log4j files

I apologize for length of this question. It's difficult to explain, even though I was fluent in English, which I'm not ;) Not really sure where post this question, because it has java, log4j library ...
5
votes
1answer
159 views

How to make a list generated by md5deep in alphabetical order of relative paths?

If I want make a md5sum list recursively, then I would use md5deep, but it starts to pop up some problems such as it won't generate the md5sum file in alphabetical order. For example, $ cd ...
0
votes
1answer
157 views

Merging CSV (single line per row) files without losing the header line

I need to merge two CSV files: datasorted1.csv and datasorted2.csv, but my headers keep getting sorted. head -n 1 datasorted1.csv datasorted2.csv > resultado.csv && tail -n +2 ...
2
votes
2answers
446 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
296 views

Sort and count number of occurrence of lines

I have Apache logfile, access.log, how to count number of line occurrence in that file? for example the result of cut -f 7 -d ' ' | cut -d '?' -f 1 | tr '[:upper:]' '[:lower:]' is a.php b.php a.php ...
1
vote
2answers
82 views

Compare and print data from different text files to one in Shell

How can I compare and print data from different text files to one in Shell. I have captures NAS details of three different boxes using SSH, now I need to combine all the three text files to one file ...
16
votes
3answers
1k views

Why is coreutils sort slower than Python?

I wrote the following script to test the speed of Python's sort functionality: from sys import stdin, stdout lines = list(stdin) lines.sort() stdout.writelines(lines) I then compared this to the ...
3
votes
1answer
146 views

Sorting lists when there are no leading zeros

I would like to sort this numerically and the sort command keys off the first character. CPL_V11.01.00_1 CPL_V11.01.00_10 CPL_V11.01.00_2 CPL_V11.01.00_3 CPL_V11.01.00_35 CPL_V11.01.00_36 ...
0
votes
3answers
47 views

sort command in unix with numeric sort

I have file1 : "$lvl=57" "$lvl=20" "$lvl=48" "$lvl=17" "$lvl=58" file2 i want : "$lvl=17" "$lvl=20" "$lvl=48" "$lvl=57" "$lvl=58" Basically numerically sort of file1
1
vote
1answer
96 views

Removing duplicate lines after comparing first pattern and special pattern

I'm looking for code to removing duplicate lines after comparing the first tab-delimited pattern: Example : (↦ = tab) car ↦ ab ↦ 38/43 car ↦ ca ↦ 2/34 house ↦ ca ↦ 34/34 house ↦ d ↦ 2/3 house ↦ ht ↦ ...
2
votes
1answer
56 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 ...
1
vote
4answers
79 views

Sort datetime string in 12-hour format

I have a log file with contents like this: 11-12-2014 - 03:03:59AM lat = 41.990516; lon = -93.430704<br> 11-12-2014 - 03:05:15AM lat = 41.001546; lon = -93.443352<br> 11-12-2014 - ...
1
vote
5answers
95 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
42 views

Different results OS X/Linux with “find PATH -mount \( -type f -o -type d \) -print0 | LC_ALL=C sort --zero-terminated > OUTPUT.txt”

this command is part of a script I use for comparing files: find test/ -mount \( -type f -o -type d \) -print0 \ | LC_ALL=C sort --zero-terminated > OUTPUT.txt // test/ is the PATH ...
2
votes
3answers
218 views

How to process a while-do loop and sort the iterated output

I'm very new at Bash Scripting so forgive my ignorance. I have a text file with last names that I am reading and processing line-by-line an average of three test scores. I need to output the lines ...
2
votes
1answer
183 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, ...
1
vote
1answer
43 views

Need to use grep and sort for matching records and display Y and N

Input file (contain column 1 with repeat value in number and second column may contain voice,email, tel, voice mail): 123,voice 123, tel 324,voice mail 345,email 123,email Output file with headers ...
1
vote
2answers
190 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 ...
2
votes
1answer
34 views

Help me understand what sort is doing here

This is a followup to this question : What does sort -n do with non numeric values? Here is my input: 1-----*** R----**** 1---***** And I run: sort -k 1.2,1.9n input.txt > output.txt Here is ...
0
votes
0answers
26 views

What does sort -n do with non numeric values? [duplicate]

I'm translating an old korne shell script that uses sort. The exact command is: sort -k 1.2,1.9n -k 1.10 -k 1.18,1.19 $LOAD_FILE > $SORTED_FILE The input file has some lines where the values in ...
5
votes
1answer
52 views

sort not working for similar entries

I am sorting a file prior to joining it with another file, using sort -k1 file1 > file1_sort When I try to join with the second file, I get an error saying file1 is not sorted. I think this is ...
1
vote
3answers
208 views

How to sort the filenames shown in grep command based on timestamp?

In the following command, how can I get the file names based on its timestamp $ grep "exit 0" a* a1.txt:+ exit 0 a2.txt:+ exit 0 a3.txt:+ exit 0 a4.txt:+ exit 0 a5.txt:+ exit 0 $ ls -latr ...
1
vote
2answers
162 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 ...