Paul H
Paul H

Reputation: 951

How do I prepend a string to each line in a text file using Windows cmd?

I have a long list where each line reads

p1 Title 1
p24 Title 2
p84 Title 3
...

I need each file to be prepended with a simple string, the initials of the book like so.

MB.p1 Title 1
MB.p24 Title 2
MB.p84 Title 3
...

I have tried the tips on Batch file to add characters to beginning and end of each line in txt file and How do you loop through each line in a text file using a windows batch file?

Upvotes: 5

Views: 11226

Answers (1)

Paul H
Paul H

Reputation: 951

In my case I found that the easiest way was to use a combination of the two links posted above:

for /f "tokens=*" %a in (input.txt) do (echo MB.%a) >> output.txt

Upvotes: 3

Related Questions