New answers tagged

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" (...
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 ...
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 ...

Top 50 recent answers are included