New answers tagged sort
4
votes
Accepted
Choose columns with sort and cut in a csv with a comma delimiter ',' ignoring data on quotes with comma "text,text"
CSV is a structured document format. As such, simple text manipulation tools like cut (or sort, sed, or awk, unless the data is simple) are inadequate for processing CSV files safely and conveniently ...
- 307k
0
votes
How is it possible to sort ps command's CPU field?
On macOS, you can use the BSD-only -r flag to "sort by current CPU usage":
ps -aexro pcpu,cputime,pid,etime,user,args | head
There's also the -m flag to sort by "memory usage" (...
- 101
0
votes
Sort using custom pattern
in addition to grep solution, if have file records and you want to preserve an order you can use xargs where you call grep.
Let's say you have file containing some data (custom_sort.txt):
ccc
aaa
xxx
...
1
vote
Sorting a FASTA sequence file according to species names using sed
You simply need to sort the lines by fields of 3 and 4. Fields separated by |
$ sed 'N;s/\n/#/g' infile | sort -t '|' -k3,4 | tr '#' '\n'
>COLFG676-14|MZ631238|Agabus|adpressus|AEC6988|COI-5P
AATG
...
- 300
0
votes
Sorting a FASTA sequence file according to species names using sed
sort -t'|' -k3 -k4 fasta.txt
Output:
">COLFG678-14|MZ630002|Agabus|adpressus|AEC6988|COI-5P"
">COLFG678-14|MZ630002|Agabus|adpressus|AEC6988|COI-5P"
">CONOR053-14|NA|...
- 101
0
votes
Sort blocks of string on file
With GNU awk, capturing the spell name in a regular expression match, and using it as an array index, then sorting the array on its index:
gawk '
BEGIN {
RS=""
FS="\n"
}...
- 75.2k
1
vote
Why does `htop` display `$'\t'` as `?` in `sort` command?
The htop process manager displays $'\t' as ? in the sort command because it interprets the \t as a tab character, which is not a valid sorting option.
In the sort command, \t is used as a delimiter to ...
- 11
2
votes
Accepted
Pipe containing sort and awk writes too many files to disk while taking random lines from files and ultimately fails due to unavailable storage
I don't really understand why you're taking this approach and I suspect it wouldn't work anyway since rand() isn't getting reinitialized and is likely always giving the exact same output. Try it:
$ ...
- 226k
13
votes
Accepted
Why does `htop` display `$'\t'` as `?` in `sort` command?
There’s nothing wrong with your command, htop replaces control characters with question marks:
(((unsigned char)data_c[j]) >= 32 ? ((unsigned char)data_c[j]) : '?')
(characters with values less ...
- 388k
Top 50 recent answers are included
Related Tags
sort × 974text-processing × 170
awk × 132
linux × 109
bash × 104
shell-script × 80
uniq × 73
ls × 63
shell × 61
files × 61
grep × 61
find × 49
sed × 45
command-line × 43
locale × 34
date × 32
filenames × 30
scripting × 22
csv × 20
numeric-data × 20
join × 19
pipe × 17
cut × 16
disk-usage × 15
coreutils × 15