Created
September 16, 2014 04:38
-
-
Save William-Yeh/6ae510e6e6e20efe1f41 to your computer and use it in GitHub Desktop.
Extract a range of lines from stdin and print to stdout.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Extract a range of lines from stdin and print to stdout. | |
# | |
# Usage: | |
# | |
# head2tail.sh starting-line [number-of-lines] | |
# | |
# Example: | |
# | |
# - Extract lines 10--16 from input-file: | |
# $ cat input-file | head2tail.sh 10 6 | |
# | |
# @see http://unix.stackexchange.com/questions/47407/cat-line-x-to-line-y-on-a-huge-file/47414#47414 | |
# | |
STARTING_LINE=$1 | |
NUMBER_OF_LINES=${2:-9876543210} | |
if [ $# -lt 1 ]; then | |
echo "Extract a range of lines from stdin and print to stdout.." | |
echo "Usage: head2tail.sh starting-line [number-of-lines]" | |
exit 1 | |
fi | |
# < inputfile tail -n +"10" | head -n "6" > outputfile | |
tail -n +"${STARTING_LINE}" | head -n "${NUMBER_OF_LINES}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment