views:

127

answers:

2

Question: I've several text files containing sql create table/column/view/storedProcedure textfiles. Now I want to merge the textfiles into one textfile.

I go into the directory, and type:

type *.sql >> allcommands.sql

Now to problem is I should add the text ' GO ' after every file's content.

I can append Go by doing

type *.sql >> allcommands.sql & echo  GO  >> allcommands.sql

But this only inserts go once. How can I accomplish this with DOS commands ?

A: 

Use copy to concatenate the first file with a file with "GO" text, then concatenate again with the second file.

mcandre
That would work, but he would have to manually specify the order of the files to copy.. This would not be able to be done with a "*.sql". And that would be more work than just typing the word "GO" in manually.
David Stratton
+5  A: 

You want something like this:

for %%f in (*.sql) do type %%f >>allcommands.sql & echo GO >> allcommands.sql

The %% is for use in a batch file. If you're not running it from a batch file you only need single % signs.

Gabe
+1. Nice to be proven wrong with a good answer like that, and learn something new.
David Stratton