#!/bin/ksh #This shellscript is chopoff. Chop off the first n bytes from a file. If the #file contains less than n bytes, turn it into an empty file. Write the chopped #off bytes to the standard output. #Sample use: chopoff 10 myfile > firsttenbytes if [[ $# -ne 2 ]] then echo $0: requires exactly 2 command line arguments 1>&2 exit 1 fi if [[ ! $1 == +([0-9]) ]] then echo $0: 1st argument $1 must be a non-negative integer 1>&2 exit 2 fi if [[ ! -f $2 ]] then echo $0: 2nd argument $2 must be a filename 1>&2 exit 3 fi if [[ ! -w $2 ]] then echo $0: need permission to overwrite the file $2 1>&2 exit 4 fi /usr/local/bin/head -c$1 $2 /usr/local/bin/tail -c+$(($1 + 1)) $2 > /tmp/$$ mv /tmp/$$ $2 exit 0