|
Answer» I would like to search a txt file and replace string with another! need help! input is attached file!
STR=PPRINT TLAXIS AX -0.7477942 AY 0.0140900 AZ 0.6637812
echo on setlocal enabledelayedexpansion set txtfile=%LOC%\%FILE%.vec set newfile=%LOC%\%FILE%.apt if exist "%newfile%" del /f /q "%newfile%" echo. * * * Processing Supplied Vector! * * * echo. set search=Search_String=%SWAP% set replace=Replace_With=%STR%
echo. * * * Processing Please WAIT! * * * for /f "tokens=*" %%a in (%txtfile%) do ( set newline=%%a call set newline=%%newline:%search%=%replace%%% call echo %%newline%% >>%newfile% ) echo. echo. * * * Completed * * * :forend :more %newfile% echo.
:eof
[recovering disk space - old ATTACHMENT deleted by admin]what is %SWAP%? instead of SHOWING the code, why don't you SHOW some SAMPLE input, show what you want to replace, and show your final output?sorry this set was missing from example!
SET SWAP=PPRINT Project number :
replace "PPRINT Project number :" with
"PPRINT TLAXIS AX -0.7477942 AY 0.0140900 AZ 0.6637812" Any Ideas? THANKS in Advance for enybodies Help!
Code: [Select]echo off
set infilename=5axis_example.aptsource set outfilename=Whatever.ext
set LineToReplace=PPRINT Project number : set ReplacementLine=PPRINT TLAXIS AX -0.7477942 AY 0.0140900 AZ 0.6637812
if exist "%outfilename%" del "%outfilename%"
for /f "delims=" %%A in (%infilename%) do ( if "%%A"=="%LineToReplace%" ( echo %ReplacementLine%>>"%outfilename%" ) else ( echo %%A>>"%outfilename%" ) )
echo Script finished echo. pause THANK's Salmon Trout! Works GREAT!
|