Skip to main content
Ed's suggestion
Source Link
Philippos
  • 13.8k
  • 2
  • 42
  • 82

With GNU sort and GNU split, you can do

split -l 20 file.txt --filter "sort -knk 4|tail -n 1" 

The file gets splitted in packets of 20 lines, then the filter option filters each packet by the given commands, so they get sorted numerically by the 4th key and only the last line (highest value) extracted by tail.

With GNU sort and GNU split, you can do

split -l 20 file.txt --filter "sort -k 4|tail -n 1" 

The file gets splitted in packets of 20 lines, then the filter option filters each packet by the given commands, so they get sorted by the 4th key and only the last line (highest value) extracted by tail.

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 given commands, so they get sorted numerically by the 4th key and only the last line (highest value) extracted by tail.

Source Link
Philippos
  • 13.8k
  • 2
  • 42
  • 82

With GNU sort and GNU split, you can do

split -l 20 file.txt --filter "sort -k 4|tail -n 1" 

The file gets splitted in packets of 20 lines, then the filter option filters each packet by the given commands, so they get sorted by the 4th key and only the last line (highest value) extracted by tail.