Page 1 of 1

Trying to insert text to end of every line

Posted: 26 Sep 2016 15:08
by mungurk@gmail.com
Hello DOSTips community,
I have a file with about 300 lines of text in it. We need to add the exact same phrase at the end of every line.

Example Text:
Pardon the rude baby
Slugs never behave themselves
Pebbles itch ferociously

Trying to get:
Pardon the rude baby please
Slugs never behave themselves please
Pebbles itch ferociously please

Disclaimer: I have already searched through Google and found some postings that are close, but not quite what I am looking for.

thanks

Re: Trying to insert text to end of every line

Posted: 26 Sep 2016 15:47
by foxidrive
This uses a native Windows batch script called Jrepl.bat written by Dave Benham
Put it in the same folder, or in a folder that is on the system path.

viewtopic.php?f=3&t=6044
or download it from Dropbox (unblock it after downloading): https://www.dropbox.com/s/4otci4d4s8x5ni4/Jrepl.bat

Code: Select all

call jrepl "^(.*)" "$1 please" /f "your file.txt" /o -


Test the above on a copy of your file.
It modifies the file itself with the - switch after the /o output switch.

You can replace the - with a new filename if you prefer.

Re: Trying to insert text to end of every line

Posted: 26 Sep 2016 16:27
by batchcc
Here's another way http://stackoverflow.com/questions/1002 ... n-txt-file

Code: Select all

@echo off
setLocal EnableDelayedExpansion
for /f "tokens=* delims= " %%a in (input.txt) do (
set /a N+=1
echo ^"%%a^",>>output.txt
)

Ps I had the same problem and it took me forever to find this on google.

Re: Trying to insert text to end of every line

Posted: 26 Sep 2016 19:43
by Squashman
batchcc wrote:Here's another way http://stackoverflow.com/questions/1002 ... n-txt-file

Code: Select all

@echo off
setLocal EnableDelayedExpansion
for /f "tokens=* delims= " %%a in (input.txt) do (
set /a N+=1
echo ^"%%a^",>>output.txt
)

Ps I had the same problem and it took me forever to find this on google.


:?:

Re: Trying to insert text to end of every line

Posted: 26 Sep 2016 20:41
by dbenham
foxidrive wrote:This uses a native Windows batch script called Jrepl.bat written by Dave Benham
Put it in the same folder, or in a folder that is on the system path.

viewtopic.php?f=3&t=6044
or download it from Dropbox (unblock it after downloading): https://www.dropbox.com/s/4otci4d4s8x5ni4/Jrepl.bat

Code: Select all

call jrepl "^(.*)" "$1 please" /f "your file.txt" /o -


Test the above on a copy of your file.
It modifies the file itself with the - switch after the /o output switch.

You can replace the - with a new filename if you prefer.

There is a simpler solution using JREPL

Code: Select all

call jrepl "$" " please" /f "yourFile.txt" /o -


Dave Benham

Re: Trying to insert text to end of every line

Posted: 26 Sep 2016 23:35
by foxidrive
foxidrive wrote:This uses a native Windows batch script called Jrepl.bat written by Dave Benham

or download it from Dropbox (unblock it after downloading): https://www.dropbox.com/s/4otci4d4s8x5ni4/Jrepl.bat

The file on dropbox has been updated if you used that one.

Re: Trying to insert text to end of every line

Posted: 27 Sep 2016 08:19
by mungurk@gmail.com
Thank you so much to all who replied

Re: Trying to insert text to end of every line

Posted: 27 Sep 2016 09:55
by Aacini
Perhaps a simpler solution would be easier to understand:

Code: Select all

@echo off
(for /F "delims=" %%a in (input.txt) do echo %%a please) > output.txt
move /Y output.txt input.txt

Antonio