Skip to content

Instantly share code, notes, and snippets.

@stevenkaspar
Created February 19, 2019 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevenkaspar/c73c713a58def01c9324b932b6820cd5 to your computer and use it in GitHub Desktop.
Save stevenkaspar/c73c713a58def01c9324b932b6820cd5 to your computer and use it in GitHub Desktop.
Bash - Print lines from large file

Allows printing a large file by giving a line range

Helpfull when you have a large file that can't be loaded into a text editor but you want to inspect it

Usage

./print_lines.sh FILE START_LINE END_LINE
./print_lines.sh ./some-large-file.xml 1000 2000
END_LINE=$3
START_LINE=$2
NUM_LINES=$(($END_LINE - $START_LINE))
HEAD_LINE=$(($START_LINE + $NUM_LINES))
echo "LINES $START_LINE-$END_LINE"
head -n $HEAD_LINE "$1" | tail -n $NUM_LINES
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment