For Programmers: Free Programming Magazines  


Home > Archive > PERL Programming > May 2006 > insert string after line number n









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author insert string after line number n
Jane

2006-05-09, 6:58 pm

Hello,
How can I insert string after line number n? I have to insert string
after "//StartHere".
I know I could do this in awk but I already started
with Perl. I'm not asking for specific answer but an idea
or alorithm would be good starting with which functions
I can use to start.

For example I have a file that has:
....
this is a test.
And << >> another test;

(and maybe ;; // ##);
//

//StartHere
(insert strings here)
(and here)
(and here)
(and so on)
(depending how many)
.....

Thanks.
J

Paul Lalli

2006-05-09, 6:58 pm

Jane wrote:
> How can I insert string after line number n?


Please read the Perl FAQ *before* asking hundreds of people around the
world to read it to you.

$ perldoc -q insert
Found in /opt2/Perl5_8_4/lib/perl5/5.8.4/pod/perlfaq5.pod
How do I change one line in a file/delete a line in a
file/insert a line in the middle of a file/append to the
beginning of a file?


Paul Lalli

Joe Smith

2006-05-10, 6:58 pm

Jane wrote:
> How can I insert string after line number n?
> I know I could do this in awk ...


man a2p
NAME
a2p - Awk to Perl translator
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com