Tagged Questions
4
votes
2answers
134 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 ...
1
vote
1answer
167 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 ...
0
votes
1answer
70 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
80 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 ...
2
votes
2answers
64 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
235 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 ...
1
vote
3answers
116 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 ...
4
votes
1answer
750 views
How to find out common elements between two files?
For an example, I have 2 files having following info:
File #1:
12
13
14
15
File #2:
12 1
13 2
14 2
15 6
16 7
17 8
Output File:
1
2
2
6
In the output file, I want only the second column ...
3
votes
4answers
231 views
Sort input file by the results of a regex
I'd like to sort a file based on the results of a regex expression. For example, if I have the following property declarations in Obj-C
@property (nonatomic, strong) id <AlbumArtDelegate, ...
5
votes
2answers
108 views
Sort fields inline
I'm trying to sort within a line of input over an unknown number of fields:
Input:
ab bc
bc ab
cd ef bc
bc cd ef
cd bc ab
ef ab bc cd gh
Output:
ab bc
ab bc
bc cd ef
bc cd ef
ab cb cd
ab bc cd ...
5
votes
2answers
237 views
sort every field numerically, varying field counts
I'm trying to sort some data using sort. I noticed it was sorting by digit rather than number, so I added the -n flag. It then seemingly only numerically sorts on the first field though. Breaking it ...
4
votes
1answer
467 views
Linux sort second last column
I would like know how to sort the second last column ? It has the word "days=" in front of the number. I'm able to get the column with awk '{print $(NF-1)}', but sorting is wrong.
457000 ...
5
votes
3answers
665 views
How to sort (by whatever key) BibTex entries in `.bib` file?
I work with LaTeX and do versioning with Git. For bibliography management I use Mendeley.
The problem is that each time Mendeley synchronizes it's .bib exports,
they are in different order, what ...
6
votes
2answers
1k views
sort inplace - like sed --in-place - exists?
Am I blind or is there no option like --in-place for sort?
In order to save results to the input file, sed uses -i (--in-place).
Redirecting the output of sort to the input file
sort < f > f
...
6
votes
4answers
290 views
Fastest way to determine if two sorted lists contain unique elements
I have two sorted files A and B where the size of A is much greater than B, e.g. A is 100GB while B is 50MB. I want to quickly determine if there are any lines in B that are contained in A, stopping ...
3
votes
2answers
576 views
Where has my `uniq` or `sort -u` line gone, with some unicode characters
What is going on in the following code snippet? I'm not getting my expected output.
I'd think it was a bug, but it happens for 2 different programs (uniq and sort), so I suspect it is something ...
14
votes
5answers
3k views
sort but keep header line in the at the top?
I am getting output from a program that first produces one line that is a bunch of column headers, and then a bunch of lines of data. I want to cut various columns of this output and view it sorted ...
3
votes
1answer
2k views
How to numerical sort by last column?
I have this input:
sdkxyosl 1
safkls 2
asdf--asdfasxy_asd 5
dkd8k jasd 29
sdi44sw 43
asasd afsdfs 10
rklyasd 4
I need this output:
sdi44sw 43
dkd8k jasd 29
asasd afsdfs 10
asdf--asdfasxy_asd 5
...
8
votes
5answers
553 views
How intelligent are unix utilities?
Unix utilities like sort, find, grep, diff et al are very handy to perform quick tasks, sometimes without writing any code at all.
I wanted to know what algorithms do they internally use and how do ...
4
votes
1answer
515 views
Is there a search utility which can binary split search a large sorted (sequential) text file?
Yes, I know it sounds odd. Sequential and Binary-splits don't mix.. That is unless the sequence is the byte offset within the file itself...
I've scrambled together a binary split search in bash ...
25
votes
8answers
4k views
how do you sort du output by size?
How do you sort du -sh /dir/* by size? I read one site that said use | sort -n but that's obviously not right. Here's an example that is wrong.
[~]# du -sh /var/* | sort -n
0 /var/mail
1.2M ...
5
votes
2answers
676 views
sort output by column
I'd like to take this command find -maxdepth 1 -type d | while read -r dir; do printf "%s:\t" "$dir"; find "$dir" | wc -l; done ( from here ). which has an output of basically
./kennel: 11062
...