LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-27-2010, 10:57 PM   #1
hattori.hanzo
Member
 
Registered: Aug 2006
Posts: 168

Rep: Reputation: 15
Display file from line # to end of file


I know how to display contents at the end of beginning of a file or even at specific lines but how to you display a file from line # to the end of the file?

Thanks & Regards,
 
Old 10-27-2010, 11:06 PM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 650Reputation: 650Reputation: 650Reputation: 650Reputation: 650Reputation: 650
Code:
#!/bin/bash

startline=10
cat $1 | perl -nle "print unless $. < $startline"
 
1 members found this post helpful.
Old 10-27-2010, 11:07 PM   #3
hattori.hanzo
Member
 
Registered: Aug 2006
Posts: 168

Original Poster
Rep: Reputation: 15
Thanks.

I just found out this appears to work also:

Code:
sed -n 'line#,$p' file
Where line# is the line you want to start from.

Update: Hmmm. This doesnt work in a bash script as $p gets expanded and errors out. Tried double quotes but no go. :-(

Last edited by hattori.hanzo; 10-27-2010 at 11:23 PM.
 
Old 10-27-2010, 11:59 PM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,425

Rep: Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826
Quote:
Update: Hmmm. This doesnt work in a bash script as $p gets expanded and errors out. Tried double quotes but no go. :-(
Actually $p would only get expanded in a script if you do use double quotes. Single quotes and it works just fine for me.
 
Old 10-28-2010, 12:46 AM   #5
hattori.hanzo
Member
 
Registered: Aug 2006
Posts: 168

Original Poster
Rep: Reputation: 15
Thanks grail but I am using a variable for the line number which is causing me the issue.

Code:
sed -n '$LINES,$p' file
 
Old 10-28-2010, 01:29 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,425

Rep: Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826
Well that changes things, so like whenever you don't want special stuff to happen, just escape it:
Code:
sed -n "$LINE,\$p" file
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
No new line at end of file? What does this mean? BajaNick Programming 12 05-19-2014 09:39 PM
End-of-line Characters missing from last line of md5 file. Md5sum fails mehorter Linux - General 5 06-29-2009 09:56 PM
C++: no new line at the end of file Cyhaxor Programming 4 01-27-2009 05:11 PM
C: fread to read a file line by line until the end Blue_muppet Programming 2 09-19-2008 10:42 AM
warning: no new line at end of file? Four Programming 5 01-07-2006 01:21 AM


All times are GMT -5. The time now is 07:17 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration