[SLUG] command line question

From: Ed Centanni (ecentan1@tampabay.rr.com)
Date: Sun Jul 06 2003 - 17:11:34 EDT


Looking for a command to print a section of a file specifed by a begin
character offset and an end character offset. Assuming such a command
is called "mid" then

mid 30 60 somefile

would output characters starting at offset 30 thru offset 60 of the file.

cut only works on LINES in a file so I cooked up a script using head and
tail that does the trick:

# validate arguments
# ...
START=$1
END=$2
FILENAME=$3
LENGTH=$(($END - $START))
head -c$END $FILENAME | tail -c$LENGTH

I guess dd would do it too, but is there something already existing
analogous to head and tail (mid, belly, navel, waist, abs, gut, hips,
rib?!) that does this?

Ed.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 18:47:22 EDT