Skip to content

Instantly share code, notes, and snippets.

@mollifier
Created September 5, 2013 15:14
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 mollifier/6451528 to your computer and use it in GitHub Desktop.
Save mollifier/6451528 to your computer and use it in GitHub Desktop.
開始行と終了行を指定して、ファイルのその範囲内だけを出力するシェルの関数
# 開始行と終了行を指定して、ファイルのその範囲内だけを出力するシェルの関数です。
# bash, zsh で動作します。
# 使い方の例
# body 10,20 file1.txt
function body() {
if [[ $# -eq 0 || "$1" == "-h" || "$1" == "--help" ]] ; then
cat << EOF
usage: $0 [START],[END] [FILE]
Output FILE from START to END line.
If START isn't specified, read FILE from the first line.
If END isn't specified, read FILE to the last line.
EOF
return
fi
local exp="${1}"
shift
exp=$(echo "$exp" | sed -e 's/^,/1,/' -e 's/,$/,$/')
sed -n -e "${exp}p" $@
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment