LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Display file from line # to end of file (https://www.linuxquestions.org/questions/linux-newbie-8/display-file-from-line-to-end-of-file-840876/)

hattori.hanzo 10-27-2010 09:57 PM

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,

kbp 10-27-2010 10:06 PM

Code:

#!/bin/bash

startline=10
cat $1 | perl -nle "print unless $. < $startline"


hattori.hanzo 10-27-2010 10:07 PM

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. :-(

grail 10-27-2010 10:59 PM

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.

hattori.hanzo 10-27-2010 11:46 PM

Thanks grail but I am using a variable for the line number which is causing me the issue.

Code:

sed -n '$LINES,$p' file

grail 10-28-2010 12:29 AM

Well that changes things, so like whenever you don't want special stuff to happen, just escape it:
Code:

sed -n "$LINE,\$p" file


All times are GMT -5. The time now is 10:36 PM.