see content of FILE from line to line
This commit is contained in:
parent
c714789432
commit
625bc38673
|
@ -0,0 +1,49 @@
|
||||||
|
#!/bin/bash
|
||||||
|
################################################################################
|
||||||
|
# 'from2.sh', created by motius, on 2017-08-03
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
# vars
|
||||||
|
USAGE="usage: from2 <file> <from_line> <to_line>"
|
||||||
|
CAT=/bin/cat
|
||||||
|
HEAD=/usr/bin/head
|
||||||
|
TAIL=/usr/bin/tail
|
||||||
|
WC=/usr/bin/wc
|
||||||
|
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# test number of arguments
|
||||||
|
[ $# -ne 3 ] && echo "${USAGE}" && exit 1
|
||||||
|
|
||||||
|
# test if file
|
||||||
|
[ -f "${1}" ] || exit 2
|
||||||
|
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# test numbers
|
||||||
|
case "${2}" in
|
||||||
|
''|*[!0-9]*) exit 3 ;;
|
||||||
|
esac
|
||||||
|
case "${3}" in
|
||||||
|
''|*[!0-9]*) exit 4 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# test if $2 <= $3
|
||||||
|
[ "${2}" -gt "${3}" ] && exit 5
|
||||||
|
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# test if enough lines
|
||||||
|
LINES=$(${WC} -l "${1}" | cut -d ' ' -f1)
|
||||||
|
[ "${LINES}" -lt "${2}" ] && exit 6
|
||||||
|
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# run
|
||||||
|
${CAT} "${1}" | ${HEAD} -n "${3}" | ${TAIL} -n $(($3-$2+1))
|
||||||
|
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# EOF 'from2.sh'
|
||||||
|
################################################################################
|
||||||
|
|
Loading…
Reference in New Issue