1.

Solve : Dos Search & Replace STR?

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


Discussion

No Comment Found