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

Reply
 
Search this Thread
Old 08-29-2008, 01:59 PM   #1
gctaylor1
LQ Newbie
 
Registered: Dec 2006
Posts: 21

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

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

Rep: Reputation: 72
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 02:55 PM.
 
Old 08-29-2008, 06:42 PM   #3
gctaylor1
LQ Newbie
 
Registered: Dec 2006
Posts: 21

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


Reply

Tags
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


All times are GMT -5. The time now is 04:14 AM.

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
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration