New answers tagged sort
1
vote
Select greatest numbered filename
1-liner:
# for numerical order
find . -maxdepth 1 -name '*.dat' -print | sort -rV | head -n1
# for alphabetical order
find . -maxdepth 1 -name '*.dat' -print | sort -r | head -n1
Note: You can use ...
2
votes
How to sort each 20 lines in a 1000 line file and save only the sorted line with highest value in each interval to another file?
Using the DSU (Decorate/Sort/Undecorate) idiom with any awk+sort+cut:
$ awk -v OFS='\t' '(NR==1) || ($1<p){b++} {p=$1; print b, $0}' file |
sort -k5,5rn | awk '!seen[$1]++' | sort -k1,1n | cut -...
6
votes
Accepted
How to sort each 20 lines in a 1000 line file and save only the sorted line with highest value in each interval to another file?
With GNU sort and GNU split, you can do
split -l 20 file.txt --filter "sort -nk 4|tail -n 1"
The file gets splitted in packets of 20 lines, then the filter option filters each packet by the ...
15
votes
How to sort each 20 lines in a 1000 line file and save only the sorted line with highest value in each interval to another file?
Via awk:
NR%20==1 {max=$4 ; line=$0}
{ if ($4>max) {max=$4;line=$0} }
NR%20==0 {print line}
Top 50 recent answers are included
Related Tags
sort × 944text-processing × 162
awk × 126
linux × 108
bash × 102
shell-script × 79
uniq × 71
ls × 63
files × 61
shell × 60
grep × 56
find × 47
sed × 43
command-line × 41
locale × 33
date × 32
filenames × 30
scripting × 22
join × 19
numeric-data × 18
csv × 17
pipe × 16
disk-usage × 15
coreutils × 15
timestamps × 13