Created
September 5, 2013 15:14
-
-
Save mollifier/6451528 to your computer and use it in GitHub Desktop.
開始行と終了行を指定して、ファイルのその範囲内だけを出力するシェルの関数
This file contains hidden or 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
# 開始行と終了行を指定して、ファイルのその範囲内だけを出力するシェルの関数です。 | |
# 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