Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
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 ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1126174]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2025-06-18 05:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.