Skip to content

Instantly share code, notes, and snippets.

@cGuille
Created January 10, 2018 16:24
Show Gist options
  • Save cGuille/4d232200c9b61fb873b9863b3a6cb5bb to your computer and use it in GitHub Desktop.
Save cGuille/4d232200c9b61fb873b9863b3a6cb5bb to your computer and use it in GitHub Desktop.
Slice a text file.
#!/usr/bin/env bash
# Output lines of stdin from $1 to $2.
# $1 and $2 can be line numbers or patterns. Examples:
# slice 10 20 # keep lines 10 to 20
# slice /foo/ /bar/ # keep lines from the one matching foo to the one matching bar.
# slice 31703 '/<\/Product>/' # keep lines from number 31703 to the first one matching </Product>
sed "$1,$2!d" -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment