How can you do different things on certain lines in a text filedivided by separators?

H

hans

How can you do different things on lines in a file divided in rages,
for example:

aaa
..
..
.. insert "aaa" on every line between aaa and bbb
..
bbb
..
..
.. insert "bbb" on every line between bbb and ccc
..
..
ccc
..
.. etc.
..
 
J

J. Gleixner

hans said:
How can you do different things on lines in a file divided in rages,
for example:

What do you have so far?

perldoc -f open
perldoc perldocfaq6
 
G

George Mpouras

hans said:
How can you do different things on lines in a file divided in rages,
for example:

aaa
.
.
. insert "aaa" on every line between aaa and bbb
.
bbb
.
.
. insert "bbb" on every line between bbb and ccc
.
.
ccc
.
. etc.
.



while(<DATA>)
{
if ( /aaa/ .. /bbb/ ) {
print "line between aaa and bbb : $_" }

if ( /bbb/ .. /ccc/ ) {
print "line between bbb and ccc : $_" }
}


__DATA__
aaa
hello1
hello2
hello3
bbb
world1
world2
world3
ccc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top