Skip to content

Instantly share code, notes, and snippets.

@zhester
Created August 18, 2014 16:34
Show Gist options
  • Save zhester/c697d43d3ca84b14f6be to your computer and use it in GitHub Desktop.
Save zhester/c697d43d3ca84b14f6be to your computer and use it in GitHub Desktop.
Copy a range of lines from a source file into another file.
#!/usr/bin/sh
#############################################################################
#
# Copy a range of lines from a source file into another file.
#
# Usage:
# range.sh <input> <first row> <last row> [<output>]
#
#############################################################################
# Go ahead and output what's going on to stdout.
set -e
set -x
# Initialize values according to user input.
_out=${4-'output'}
_start=`expr $3 - 1`
_count=`expr $3 - $2 + 1`
# Copy the desired range of lines to the output file.
( tail -n +$_start $1 | head -n $_count ) > $_out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment