#!/bin/sh -eu
#
# cat-region - prints text from FILENAME starting at FROM_OFFSET ending at UPTO_OFFSET
# optionally extending the region by CONTEXT_SIZE in both directions if given

if [ "$#" -lt 3 ]; then
  printf '%s\n' "\
Usage: $(basename "$0") <FILENAME> <FROM_OFFSET> <UPTO_OFFSET> [CONTEXT_SIZE]"
  exit 1
fi

file="$1"
from="$2"
upto="$3"
wing="${4:-0}"
from=$((from - wing))
upto=$((upto + wing))
size=$((upto - from))

# shellcheck disable=SC2250
dd status=none bs=1 skip="$from" count="$size" if="$file"
