Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Variable Declarations!
- word_count=$(wc -l $3 | cut -d ' ' -f 1)
- #Error Checking!
- # check if there are exactly 3 arguments given
- if [[ "$#" -ne 3 ]]; then
- echo "Error: "$0" needs 3 arguments!"
- echo "usage: "$0" int int file_name"
- exit
- elif [[ "$#" -eq 3 ]]; then
- # check if file exists
- if [[ -e "$3" ]]; then
- # check if the first num is less than or equal to the second num
- if [[ "$1" -le "$2" ]]; then
- # check if the number of lines in the file is greater than the last line to be printed
- if [[ $word_count -gt $2 ]]; then
- head -"$1" "$3"| tail -"$2"
- else
- echo "Error! File has less lines than the last line to be printed, print less lines!"
- exit
- fi
- else
- echo "Error! Invalid line paramaters: first argument must be less than the second!"
- exit
- fi
- else
- echo "Error: File does not exist!"
- exit
- fi
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement