Trying to insert text to end of every line

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
mungurk@gmail.com
Posts: 6
Joined: 26 Sep 2016 15:02

Trying to insert text to end of every line

#1 Post by mungurk@gmail.com » 26 Sep 2016 15:08

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

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Trying to insert text to end of every line

#2 Post by foxidrive » 26 Sep 2016 15:47

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.

batchcc
Posts: 139
Joined: 17 Aug 2015 06:05
Contact:

Re: Trying to insert text to end of every line

#3 Post by batchcc » 26 Sep 2016 16:27

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.

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Trying to insert text to end of every line

#4 Post by Squashman » 26 Sep 2016 19:43

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.


:?:

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Trying to insert text to end of every line

#5 Post by dbenham » 26 Sep 2016 20:41

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

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Trying to insert text to end of every line

#6 Post by foxidrive » 26 Sep 2016 23:35

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.

mungurk@gmail.com
Posts: 6
Joined: 26 Sep 2016 15:02

Re: Trying to insert text to end of every line

#7 Post by mungurk@gmail.com » 27 Sep 2016 08:19

Thank you so much to all who replied

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Trying to insert text to end of every line

#8 Post by Aacini » 27 Sep 2016 09:55

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

Post Reply