]>
zdv2.bktei.com Git - BK-2020-03.git/blob - unitproc/bkt-printl
   4     function yell
() { echo "$0: $*" >&2; } # print script path and all args to stderr 
   5     function die
() { yell 
"$*"; exit 111; } # same as yell() but non-zero exit status 
   7         # Desc: Display script usage information 
  12         yell 
"printl [int] [int] ([path])"; 
  15         yell 
"printl 5 17 somefile.txt" 
  16     }; # Display information on how to use this script. 
  18         # Desc: Prints ranges of lines 
  19         # Usage: printl [int] [int] [path] 
  21         # Example: printl 5 17 somefile.txt  # prints lines 5-17 
  22         # Depends: Bash 5.1.16 
  26         # Require first two args be integers 
  28         if [[ ! "$start" =~ 
$re ]]; then 
  30             die 
"FATAL:First argument (start line number) not an integer:$(declare -p start)"; 
  32         if [[ ! "$end" =~ 
$re ]]; then 
  34             die 
"FATAL:Second argument (end line number) not an integer:$(declare -p end)"; 
  37         # Require between 2 and 3 arguments are provided 
  38         if [[ $# -ge 4 ]]; then 
  40             die 
"FATAL:Too many arguments:$#"; 
  42         if [[ $# -le 1 ]]; then 
  44             die 
"FATAL:Too few arguments:$#"; 
  47         # Handle 3 argument case (int int file) 
  48         if [[ $# -eq 3 ]] && [[ -f "$3" ]]; then 
  51         elif [[ $# -eq 3 ]] && [[ ! -f "$3" ]]; then 
  53             die 
"FATAL:Third argument not a file."; 
  56         # Handle 2 argument case (int int) 
  57         if [[ $# -eq 2 ]]; then 
  63         tail -n+${start} "$input" | 
head -n$
((end 
- start 
+ 1));