Created
November 16, 2012 15:02
-
-
Save nogajun/4087978 to your computer and use it in GitHub Desktop.
Himeji IT Study Vol.11 L-1 GP 3.tail
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
parse_options(){ | |
N=5 # default line number | |
while getopts "n:" OPT; do | |
case ${OPT} in | |
n) N="$OPTARG" ;; | |
esac | |
done | |
shift $(($OPTIND-1)) | |
FILENAME=$@ | |
} | |
# sed version | |
sed_version(){ | |
if [ "${START_LINE}" -gt "0" ]; then | |
sed "1,${START_LINE} d" ${FILENAME} | |
else | |
cat ${FILENAME} | |
fi | |
} | |
# while version | |
while_version(){ | |
IFS=$'\n' | |
i=1 | |
while read LINE;do | |
[ ${i} -gt ${START_LINE} ] && echo "${LINE}" | |
let ++i | |
done < ${FILENAME} | |
} | |
parse_options "$@" | |
END_LINE=$(wc -l ${FILENAME}|cut -f1 -d" ") | |
START_LINE=$((${END_LINE} - ${N})) | |
#sed_version | |
while_version |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment