Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have customer pizza lists that I have saved into 5 separate .txt files from my database in this format:

Filename = 25Percent.TXT

Each list is a phone number in quotes and each list varies in length.

First question
I have two sets of variables that I would like to replace with each quote in the 5 text files.
The two variables would be like:

Var A = < Discount Pizza price for phone number is "
Var B = " 25 % >

I would like to run a batch file that reads each line in the text file and writes into another text file the following, replacing the quotes with the variables:

New Filename = 25Percentfinished.TXT
< Discount Pizza price for phone number is "555-1211" 25 % >
< Discount Pizza price for phone number is "555-1212" 25 % >
< Discount Pizza price for phone number is "555-1223" 25 % >

Then I would repeat for 30percent.txt, 35percent.txt, 40percent.txt and finally 50percent.txt file.

Second Question
I would also like to append the 5 new files together

share|improve this question
If you've got Excel, this is going to be a lot easier to do in there. – user3463 May 31 '12 at 4:01
It is generally not recommended to ask two questions at once. Each question should be asked separately. – Bob Jan 3 '13 at 17:04
appending files together is simply copy file1+file2+file3+...+fileN bigfile – SeanC Jan 3 '13 at 17:05

It's a simple for loop:

for /f "tokens=*" %%a in (25Percent.txt) do (
    echo ^< Discount Pizza price for phone number is %%a 25 %%% ^>>>25Percentfinished.txt

See for /? for usage. This processes the file line by line, reading the line into the variable %%a and appending the modified line to the other file. The < and > are escaped with ^ (making ^< and ^>) because they have a special meaning in the command prompt. The % is 'escaped' with %%% because it's also a special character, but cannot be escaped like the others.

You can combine multiple text files like so:

copy file1.txt + file2.txt + file3.txt destination.txt

Or you can loop with type and append (>>) (this will combine all files in the current directory, in alphabetical ascending sorted order):

for %%a in (*.txt) do (
    type %%a>>destination.txt
share|improve this answer

You don't specify the OS so I'll provide a solution that'll work if you have sed available.

$ sed -e 's/^\(.*\)$/< Discount Pizza price for phone number is \1 25 % >/' < 25Percent.TXT
share|improve this answer
The OS is specified although indirectly. See: – mnmnc Jan 3 '13 at 15:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .