Hot answers tagged

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}
user avatar
  • 10.8k
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 ...
user avatar
  • 11.6k
4 votes
Accepted

Difference between sort -u and uniq -u

No, they're not the same. For one, sort would sort the list first; and second, uniq -u prints only those lines that are "unique" in each given run, the ones that don't have an identical ...
user avatar
  • 116k
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 -...
user avatar
  • 22.5k
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 ...
user avatar

Only top scored, non community-wiki answers of a minimum length are eligible