Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #test if 3 arguments were specified
- if [[ $# != 3 ]]
- then
- exit 1;
- fi
- #test if $3 is readable file
- if [[ ! -r "$3" || ! -f "$3" ]]
- then
- exit 2;
- fi
- #test if $1 is positive number
- if [[ ! $1 =~ ^([1-9][0-9]*|0)$ ]]
- then
- exit 2;
- fi
- #test if $2 is positive number
- if [[ ! $2 =~ ^([1-9][0-9]*|0)$ ]]
- then
- exit 2;
- fi
- #test if $2 is at least $1
- if [ $2 -lt $1 ]
- then
- exit 2;
- fi
- #test if file have enough lines
- lines=$(wc -l "$3" | awk '{print $1}')
- if [ $lines -lt $2 ]
- then
- exit 2;
- fi
- #print desired lines
- awk -v from=$1 -v to=$2 '{if (NR >= from && NR <= to) print $0;}' "$3"
- exit 0;
Advertisement
Add Comment
Please, Sign In to add comment