Quote:
Originally Posted by rsashok
Thanks jschwal! I liked the 'tummy' command idea. I put it in my .bashrc:
function tummy() # print file section of any size, akin 'head' and 'tail'
{
if [[ ${#@} -eq 2 ]]; then
start_line=$2
end_line=$2
else
if [[ ${#@} -eq 3 ]]; then
start_line=$2
end_line=$3
else
cat <<-EOF
Usage: $0 file_name start_line end_line
Usage: $0 file_name single_line
EOF
fi
fi
sed -n "$start_line,"$end_line"p;$(($end_line+1))q" "$1"
}
|
I edited this because I was getting a sed error when run with no arguments (this is on cygwin, but it shouldn't make too much difference...)
Code:
function tummy() # print file section of any size, akin 'head' and 'tail'
{
if [[ ${#@} -eq 2 ]]; then
start_line=$2
end_line=$2
else
if [[ ${#@} -eq 3 ]]; then
start_line=$2
end_line=$3
else
cat <<-EOF
Usage: $0 file_name start_line end_line
Usage: $0 file_name single_line
EOF
fi
fi
if [[ ${#@} -gt 1 ]]; then
sed -n "$start_line,"$end_line"p;$(($end_line+1))q" "$1"
fi
}