Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 08-29-2008, 01:59 PM   #1
Registered: Dec 2006
Distribution: Red Hat
Posts: 44

Rep: Reputation: 0
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

Old 08-29-2008, 02:54 PM   #2
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 729

Rep: Reputation: 75

I don't use one-liners because I'm too clumsy at the keyboard, but both of these seem to work ... cheers, makyo
perl -ni -e "print unless( 3 == $. )" filename.txt
perl -ni -e "print if( 3 != $. )" filename.txt

Last edited by makyo; 08-29-2008 at 02:55 PM.
Old 08-29-2008, 06:42 PM   #3
Registered: Dec 2006
Distribution: Red Hat
Posts: 44

Original Poster
Rep: Reputation: 0

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.


delete, line, perl, regex, sed

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
Txt Edr.- HTML- Custom Saved Code "Snippets" WhatsOnYourBrain Linux - Software 1 04-01-2007 03:36 PM
Replacing "function(x)" with "x" using sed/awk/smth Griffon26 Linux - General 3 11-22-2006 10:47 AM
problem "make"ing gtk+ "/usr/bin/env: perl -w" caid Linux - Newbie 8 07-29-2005 04:51 AM
cannot exit normally after "nohup blablabla > output.txt &" LQYY Linux - Newbie 1 12-14-2004 10:02 AM
LFS 4.1: Stalled at Perl, "missing seperator" error from "make" SparceMatrix Linux From Scratch 1 06-07-2003 03:31 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:52 PM.

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