#!/bin/bash
#
# highest filename [howmany]
# Print howmany highest-numbered lines in file filename
# The input file is assumed to have lines that sart with numbers
#+Default for howmany is 10.
filename=$1
howmany=${2:-10}
sort -nr $filename | head -$howmany
Results:
# howmany defaults to 10
$ ./highest.sh albumns.txt
22 U2
12 Coldplay
11 Aerosmith
9 Kodaline
9 Jackson Browne
8 21 Pilots
7 Michael Jackson
6 Pitbull
6 Elton John
5 Thirty Seconds to Mars
# howmany ($2) is 5
$ ./highest.sh /auto/home/homeb/d54712/sandbox/scripts/data.d/albumns.txt 5
22 U2
12 Coldplay
11 Aerosmith
9 Kodaline
9 Jackson Browne
No comments:
Post a Comment