I am trying to insert a certain string with sp开发者_开发问答aces "sBody = " before each line in a text document. I found this answer in other forums, but it does not work? A few questions I have about this script are, should "myfile" be the full filepath? Also, this script was originally made to insert a string at the end of the file, what do I need to take out to make it insert just one string at the beginning?
Thank you for all of your answers!
@echo off > newfile & setLocal EnableDelayedExpansion
for /f "tokens=* delims=" %%a in (myfile) do (
echo STRING %%a STRING >> newfile
)
The script is creating a new file named 'newfile' reading in the original file 'myfile'. Once it's done you can delete 'myfile' and rename 'newfile' to 'myfile' if you like. This example replaces each <line> in the file with STRING <line> STRING.
@echo off
setLocal EnableDelayedExpansion
for /f "tokens=* delims=" %%a in (myfile) do (
echo STRING %%a STRING >> newfile
)
sed 's/.*/pattern &/' yourfile.txt -i
works for me, in a single command line
精彩评论