LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Can Perl do this? "sed -ie '3d' filename.txt" (https://www.linuxquestions.org/questions/programming-9/can-perl-do-this-sed-ie-3d-filename-txt-666343/)

gctaylor1 08-29-2008 01:59 PM

Can Perl do this? "sed -ie '3d' filename.txt"
 
Like the title says. I usually use sed and it works, but I'm trying to use Perl more in my everyday life to learn it. I'm hoping for a one liner that I can use and remember.

I thought this might come close but doesn't seem to cut it.
$ perl -p -i -e /3d/ filename.txt
$ perl -p -i -e '3d' filename.txt

What I can't figure out is how to specify a line number to match instead of a regex.

Using Linux/cygwin
Perl 5.8.8

Thank-you.

makyo 08-29-2008 02:54 PM

Hi.

I don't use one-liners because I'm too clumsy at the keyboard, but both of these seem to work ... cheers, makyo
Code:

perl -ni -e "print unless( 3 == $. )" filename.txt
perl -ni -e "print if( 3 != $. )" filename.txt


gctaylor1 08-29-2008 06:42 PM

Thank-you!
 
That's works great. I see what you mean about running on the command line. I may have to put that in a script after all.


All times are GMT -5. The time now is 05:43 PM.