Tagged Questions

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

learn more… | top users | synonyms

5
votes
1answer
35 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
42 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
123 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 ...
2
votes
4answers
55 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 ...
3
votes
3answers
58 views

Sorting directories by last modified date/time of the same-named contained file

Is it possible, using grep, find, etc, to sort a list of directories by the last modified date of the same-named file (e.g., file.php) within? For example: domain1/file.php (last modified 20-Jan-2014 ...
2
votes
2answers
46 views

Making sort use all CPU CORES

htop is showing that the "sort" command only uses 1 CPU CORE (on an RPM based Linux distro). How can I tell it to use all the available CPU CORES?
1
vote
4answers
123 views

Sed/awk/perl: reversing order of comma separated values, preserving other text

I have this text: LABEL1 .BYTE 01, 02, 03, 04, 05 .BYTE 01, 02, 03 I need to reverse only comma separated values order: LABEL1 .BYTE 05, 04, 03, 02, 01 .BYTE 03, 02, 01 I need ...
3
votes
2answers
248 views

How to concatenate two files in a new one and sort the output in one line

I have two files with some names in them, when I ran cat file1 file2 | sort, the terminal shows the names sorted alphabetically, but when I run cat file1 file2 > file3 | sort I don't see the sorted ...
1
vote
2answers
151 views

sort and ls — why aren't capitalized letters sorted first?

I want a sorting like this, with capitalized letters before lowercase: -rw-r--r--. 1 0 0 183 2014-10-14 20:17 ./CHECKSUMS.md5 -rw-r--r--. 1 0 0 185 2014-10-14 20:17 ./CHECKSUMS.asc ...
0
votes
1answer
34 views

Sort three columns? [closed]

sort -t $'\t' -k 1rn,1 -k 2,2rn -k 3f,4 listaprezzi 2050 900 bananas 5 1905 700 grapes 17 250 4000 oranges 10 230 9200 ...
12
votes
2answers
510 views

How does awk '!a[$0]++' work?

This one-liner removes duplicate lines from text input without pre-sorting. For example: $ cat >f q w e w r $ awk '!a[$0]++' <f q w e r $ The original code I have found on the internets ...
4
votes
2answers
50 views

Sorting strings with ANSI escape codes

I am trying to print a sorted list of all zsh options, with set options colored green and unset options colored red. I cannot get sort to work properly with on the colored lines though.The below ...
4
votes
3answers
131 views

Finding files on a Unix server and sorting by size

I have a web server where I have run out of space and it's causing issues with the WordPress sites I am running on them. I know that I have a lot of large .png files (the fact that it's PNG is a ...
0
votes
1answer
38 views

The sorted file is not saved correctly [closed]

If I sort a file, I want save it in the new one. I use for this just: sort -nk{fieldnumber} test.json > testsort.json In the output the columns are shuffled and the column, which I have sorted, ...
1
vote
1answer
21 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 ...
3
votes
1answer
152 views

Putting Files in Ascending order (not on time stamp basis) in Unix [closed]

How do I list files in Ascending manner, not on time stamp basis. EX:- Original listing A_2001 A_2002 A_2003 A_2004 B_2001 B_2002 B_2003 B_2004 Desired output:- A_2001 B_2001 A_2002 B_2002 ...
2
votes
2answers
57 views

Should I use piping or redirection for input to 'sort'

I want to do awk -F "," '{print $1 }' inputfile1.txt | sort -u > distinctOutput.txt Is this good performance-wise ? Or should I redirect / use a temp file since I think it is better to make sort ...
3
votes
2answers
112 views

Sorting by a name field?

I am trying to sort the following file http://pastebin.com/EqA2SUMy. But the part I am trying to sort is the 11 field and only if the first field is atom. Here is an example ATOM 33 CG ASP ...
0
votes
1answer
26 views

What's with `-` in filename affecting sorting order depending on platform? [duplicate]

I just checked if contents of directory on my cygwin/Win7 development system, and test embedded platform running Linux+Busybox are the same. Simple, cat * | md5sum on both (RXVT/Bash on Cygwin, serial ...
2
votes
1answer
122 views

Sort the 'last' output by month

I know that the command last | tac is enough, but I want to do it using the sort command. I cannot sort it by column, it always sorts the first one only. Using bash on Arch Linux.
7
votes
3answers
289 views

How to sort vertically and horizontally?

Before (INPUT.txt): Foo#1 Foo#2 Foo#3 Foo#4 Foo#4 Foo#5 SUM Bar#1 0 0 0 0 3 0 3 Bar#2 2 0 1 0 0 0 3 Bar#3 0 0 0 2 2 0 4 Bar#4 0 0 1 ...
3
votes
2answers
97 views

Identify lines that are out of order

I have a process that generates output mostly in lexicographically sorted order according to a (timestamp) field, but occasionally the lines will be output in the wrong order: 2014-08-14 ...
0
votes
0answers
50 views

Sorted HTML table

I need a very quick and easy way to sort HTML tables. The table rows contain images that should stay with their appropriate row. I tried pasting my HTML into Libre Office calc, but the images are not ...
1
vote
2answers
65 views

How can I sort a .txt file by two columns?

Feb 7 domainserver dovecot[37495]: auth(default): od(tjones): lookup failed for user: tjones Above is a sample output of what I'd like to sort. I'd like to sort by date on the first column, but ...
6
votes
4answers
126 views

Find newest file. Multiple Filetype restrictions

I want to write a command that gives me the newest file in a directory recursively. But that's not my only limitation. The files has to be an mp3 or a jpg file. (case insensitive prefered) I only need ...
4
votes
2answers
39 views

How to sort a collection of lines from different files?

I want to sort second line in each file by second column, and also print name of the corresponding file. I am doing it like this - rm tmp; for filename in file*; do num=`head -2 $filename | tail ...
6
votes
2answers
114 views

What should be the buffer size for the sort command?

I have a machine with 2 TB of RAM and I am running a sort command on a file of size 150G where I have specified the buffer-size as 1000G, after doing my bit of reasearch on google, I got this piece of ...
0
votes
1answer
154 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 ...
0
votes
1answer
70 views

Why am I not getting correct output with sort command [closed]

This is what I have tried so far sort /etc/passwd -t: -k1 > ~/passwd.bylogin I keep getting an error that the output is wrong. The question is: Sort the /etc/passwd file in alphabetically ...
3
votes
4answers
156 views

How to sort with a delimiter that is several characters long?

INPUT: $ cat a.txt 1FOO2FOO3 4FOO5FOO5 2FOO1FOO9 $ OUTPUT: $ cat a.txt | sort SOMEMAGIC 2FOO1FOO9 1FOO2FOO3 4FOO5FOO5 $ Question: How can I sort, if I have a several character long ...
2
votes
2answers
87 views

Removing lines with a single common field

I have a tab separated file that looks like this: 123 some text 123 some different text 334 some other text 341 more text and I want to do two things. One is to order everything numerically ...
2
votes
4answers
541 views

Sort the output of find -exec ls

Is it possible to the output of find … -exec ls -ls ; sorted alpabetically, by filename? This is my cron command: find /home/setefgge/public_html -type f -ctime -1 -exec ls -ls {} \; This command ...
2
votes
2answers
132 views

Printing lines with similar text together

I am currently working on analyzing the performance of an application. I've starting by looking at the logs generated by our application and identifying the business logic tasks that are taking more ...
3
votes
3answers
376 views

Sort comma-separated fields on each line by numeric value

I tried this: $ echo "2,3435,1" | sort -n 2,3435,1 $ sort -t',' -n test_sort.txt kill,gill,burger 110,20,30,13 $ cat test_sort.txt 110,20,30,13 kill,gill,burger Why doesn't my sort command work? ...
1
vote
3answers
45 views

How can i get the process with the biggest pid?

How can I get the process with the biggest pid using ps?
11
votes
3answers
703 views

Sorting data faster approach

I need to sort a bed file randomly 10000 times and take the top 1000 rows each time. Currently, I am using the following code: for i in {1..100}; do for j in {1..100}; do sort -R ...
8
votes
2answers
260 views

sort by hex value

Using coreutils sort, how can I sort numerically by a hexadecimal value (field)? I was expecting something along the lines of sort -k3,3x file_to_sort however, such an x does not exist. Edit: ...
-1
votes
1answer
26 views

How do I sort the signal buses with bits in ascending order?

I am trying to sort a file with signal buses. I am looking for result where the bits are in ascending order -- 2 followed by 3 and not 20. cat file1 |sort file1 cls_16_snap[2] cls_16_snap[20] ...
2
votes
3answers
72 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
1answer
40 views

sort based on column

10 awhdk; 14 hjoeow; 2 kdkld; 4 jkjdksl How to sort this based on column one (i.e the count) ? I'd want to get this output : 14 hjoeow;10 awhdk;4 jkjdksl;2 kdkld I need both the columns to be ...
2
votes
2answers
101 views

How to print top five highest numbers from a column?

I have a text file with four columns. I need to read till end of file and print the highest number from column3 (top 5 values) along with column 1. input.txt xm|340034177|ref|RT_235820.1| 139697 ...
1
vote
2answers
110 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
1answer
65 views

`sort` disregards question mark [duplicate]

I need to sort a file based on names in the first column. Some of the names end in a question mark. sort persistently ignores this question mark during sorting: sort -k 1 -t , <<TEST a?,1 a,2 ...
2
votes
2answers
181 views

Tool for viewing top N items in stream

I'm looking for an existing Linux command-line tools that can accomplish the following: Consider there is an input stream /dev/inputstream which spews an infinite stream of data that looks like this: ...
3
votes
1answer
268 views

Fastest `uniq` tool in linux

I have large text file (1.5 G), I want to know what the fastest and more reliable tool in linux is. I usualy use: awk '!x[$0]++' file.txt But when I use htop command I see my memory usage is ...
0
votes
2answers
40 views

Sorting by Last Name in the Scond Column

I'm trying to sort a file that has entries that look like so: Essie | Vaill | 14225 Hancock Dr | Anchorage | AK | 99515 907-345-0962 Please note the "|" stand for tabs of ...
2
votes
2answers
101 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 ...
6
votes
1answer
149 views

How to specify additional parameters for GNU sort's --compress-program option?

sort --compress-program=/bin/gzip works fine, but how can I pass options down to the compression programm (e.g. --best or --fast)? sort --compress-program=/bin/gzip\ --best failes with the error ...
2
votes
3answers
324 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
7answers
1k views

Sort the files in the directory recursively based on last modified date

Sort the files in the directory recursively based on last modified date I have modified a lot of files in my directory want to know what are those files by sorting them by the last modified date ...