LinuxQuestions.org
Review your favorite Linux distribution.
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

Tags used in this thread
Popular LQ Tags , , , ,

Reply
 
Thread Tools
Old 08-29-2008, 02:59 PM   #1
gctaylor1
LQ Newbie
 
Registered: Dec 2006
Posts: 16
Thanked: 0
Can Perl do this? "sed -ie '3d' filename.txt"


[Log in to get rid of this advertisement]
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.
gctaylor1 is offline  
Tag This Post , , , ,
Reply With Quote
Old 08-29-2008, 03:54 PM   #2
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Solaris, SuSE, Xandros
Posts: 566
Thanked: 3
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

Last edited by makyo; 08-29-2008 at 03:55 PM..
makyo is offline     Reply With Quote
Old 08-29-2008, 07:42 PM   #3
gctaylor1
LQ Newbie
 
Registered: Dec 2006
Posts: 16
Thanked: 0

Original Poster
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.
gctaylor1 is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

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


All times are GMT -5. The time now is 08:28 PM.

Main Menu
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
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration