Trying to insert text to end of every line
Moderator: DosItHelp
-
- Posts: 6
- Joined: 26 Sep 2016 15:02
Trying to insert text to end of every line
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
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
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
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.
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
Here's another way http://stackoverflow.com/questions/1002 ... n-txt-file
Ps I had the same problem and it took me forever to find this on google.
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
batchcc wrote:Here's another way http://stackoverflow.com/questions/1002 ... n-txt-fileCode: 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
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.batCode: 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
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.
-
- Posts: 6
- Joined: 26 Sep 2016 15:02
Re: Trying to insert text to end of every line
Thank you so much to all who replied
Re: Trying to insert text to end of every line
Perhaps a simpler solution would be easier to understand:
Antonio
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