LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-16-2007, 04:30 PM   #16
rsashok
Member
 
Registered: Nov 2006
Location: USA, CA
Distribution: RedHat, Debian
Posts: 202

Original Poster
Rep: Reputation: 31

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"
}
 
Old 09-04-2007, 09:39 AM   #17
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
Quote:
Originally Posted by rsashok View Post
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
}
 
  


Reply

Tags
bash



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ text file line by line/each line to string/array Dimitris Programming 15 03-11-2008 08:22 AM
php - Read file line by line and change a specific line. anrea Programming 2 01-28-2007 01:43 PM
SED - display text on specific line of text file 3saul Linux - Software 3 12-29-2005 04:32 PM
Display line number n from a file doctorwebbox Linux - Newbie 2 01-05-2005 02:06 PM
Display/Read line 'N' in a text file using script ganninu Linux - Newbie 2 10-13-2003 05:28 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration