LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 06-21-2010, 11:04 AM   #1
shifter
Member
 
Registered: May 2006
Distribution: Slackware, DragonFly
Posts: 233

Rep: Reputation: 30
deleting rows in text file in Perl


How can I delete rows into text file in perl?
 
Old 06-21-2010, 03:08 PM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by shifter View Post
How can I delete rows into text file in perl?
The question is incomplete/ambiguous - regardless of language.

Deletion may be based on row (i.e. line) number or on line contents.
 
Old 06-21-2010, 03:30 PM   #3
shifter
Member
 
Registered: May 2006
Distribution: Slackware, DragonFly
Posts: 233

Original Poster
Rep: Reputation: 30
I want remove rows.
For example within file with 10 rows I 'd like remove rows 7 and 8.
 
Old 06-21-2010, 04:52 PM   #4
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by shifter View Post
I want remove rows.
For example within file with 10 rows I 'd like remove rows 7 and 8.
You open input file for reading and output file for writing.

You create a counter of input file lines (actually, there is a buil-in one, so you can use it too). If your counter is less than 7 or greater than 8 you copy lines from input file into output file, else not.

Read

perldoc -f open
.
 
Old 06-28-2010, 07:10 PM   #5
Telemachos
Member
 
Registered: May 2007
Distribution: Debian
Posts: 754

Rep: Reputation: 60
It might also help you to know that the built-in $. variable holds the line number in Perl. You can use this for testing.
 
  


Reply



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
remove no data rows from a text file lothario Linux - Newbie 1 08-30-2009 07:18 AM
How to duplicate rows of text from one file to another? guest Programming 1 04-25-2009 08:14 AM
Print only specific rows in a text file Mike_V Programming 3 04-24-2009 07:18 PM
Parsing rows and column data from a file using perl dav_y2k Programming 1 10-08-2006 11:57 AM
deleting 100 rows in text file (1-100) via terminal itz2000 Linux - Newbie 5 01-17-2006 11:19 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:14 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration