Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: How to insert the content of a file into another file before/after a pattern match?

by CountZero (Bishop)
on May 09, 2015 at 06:24 UTC ( #1126174=note: print w/replies, xml ) Need Help??


in reply to How to insert the content of a file into another file before/after a pattern match?

Open both files for reading and open a new third file for writing.

In a while-loop, read file1 line by line

print each line to the third file.

test if you have reached the "architecture DEF_ARCH of fulladder_postsyn is" line and if so, read the whole of file 2 and print this to the third file.

Continue with reading and printing file1.

Close all filehandles.

unlink file1 and rename "file3" to "file1".

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

My blog: Imperial Deltronics
  • Comment on Re: How to insert the content of a file into another file before/after a pattern match?
  • Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1126174]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2021-01-25 15:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?