[shell小工具] 显示文件指定行的内容

来源:互联网 发布:阿里云香港数据中心 编辑:程序博客网 时间:2024/06/07 19:53
if [ $# -lt 2 ] ; then
    echo "USAGE: $0 {file_name} {start_line} [{end_line}]"
    exit -1 
fi


if [ $# -eq 2 ] ; then
    cat $1 | head -n $2 | tail -n 1
fi


if [ $# -gt 2 ] ; then
    cat $1 | head -n $(($2+$3-1)) | tail -n $3

fi