views:

58

answers:

2

I'm faced with the task of find and replacing multiple include files with the include file's content.

Just wondering if I'd be quicker copy / pasting than writing a bit of code to do so, or if there's a tool out there that could do this for me?

Pretty sure its a common need. I'm on Windoze btw. Any suggestions welcome.

Just to clarify a bit..

<body>
<!--#include file="content1.asp" -->
</body>

What I want to achieve is

<body>
<the html contents of content1.asp>
</body>

This is a straightforward dig into content1.asp, put in a variable, and replace <!--#include file="content1.asp" --> with the variable.

A: 

How about just a project-wide Find and Replace?

Find 'the code to include the file'. Replace with 'the actual file contents'.

You might have problems with text length limits for the replace string though. What IDE are you using?

UpTheCreek
Paul
Not sure I follow. Why do you need to do partial matches? Do you have multiple include files with the same content?
UpTheCreek
multiple include files with different content..the partial match would be performed on the filename of the include. i.e. I know that the ONLY include files in this project that I wish to search inside and replace start with a certain pattern.
Paul
+1  A: 

Here's a perl solution:


perl -pe 'if( /<!--#include file="([^"]*)" -->/ ) { $t=qx"cat $1"; s//$t/}'

The include statement must appear on a single line.

William Pursell