NickMalloy
asked on
Adding characters to the beginning of each line
How can I add some text to the beginning of each line in a txt file within notepad?
ASKER
awesome. How would I extend this to add some text to the end of each line?
you just have to edit the echo line - this is where the text is combined with the record. %%i represents the original record. !x! is the new text.
for example, to add the text at the end of the line you would change this to:
echo %%i!x! >> new_file.txt
for example, to add the text at the end of the line you would change this to:
echo %%i!x! >> new_file.txt
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
REM Add text to the beginning of each record
REM Change $text to the correct string you want appended to each record
Echo off
cls
ECHO Processing Records - please wait
ECHO.
REM create a environmental variable with the text in it
set $text=TEXT TO BE APPENDED
REM process FILE.TXT
IF exist new_file.txt del new_file.txt
setlocal EnableDelayedExpansion
set x=%$text%
for /f "delims=" %%i in (file.txt) do (
echo !x!%%i >> new_file.txt
)
REM output file is new_file.txt