

InterviewSolution
Saved Bookmarks
1. |
Solve : Dos String Search & Replace Columns? |
Answer» <html><body><p>HI <br/><a href="https://interviewquestions.tuteehub.com/tag/question-25051" style="font-weight:bold;" target="_blank" title="Click to know more about QUESTION">QUESTION</a>, is it possible to do the following example with batch file commands?<br/><br/>Replace all lines that start with GOTO in a file starting with column 43 to 71 that <a href="https://interviewquestions.tuteehub.com/tag/contains-11473" style="font-weight:bold;" target="_blank" title="Click to know more about CONTAINS">CONTAINS</a> spaces with three variables %%u %%v %%w <br/>(-0.7478, 0.0141, 0.6638) then add <a href="https://interviewquestions.tuteehub.com/tag/balance-238529" style="font-weight:bold;" target="_blank" title="Click to know more about BALANCE">BALANCE</a> of line (PT 7) for example below!<br/><br/><br/>Example;<br/><br/> FROM<br/>PPRINT Vue : second<br/>GOTO / 409.33480, -18.96415, 7.79821 PT 7<br/>GOTO / 419.47490, -24.89781, 19.34762 PT 8<br/><br/> TO<br/>PPRINT Vue : second<br/>GOTO / 409.33480, -18.96415, 7.79821 -0.7478, 0.0141, 0.6638 PT 7<br/>GOTO / 419.47490, -24.89781, 19.34762 -0.7478, 0.0141, 0.6638 PT 8you can download <a href="http://gnuwin32.sourceforge.net/packages/sed.htm">sed </a>or <a href="http://gnuwin32.sourceforge.net/packages/gawk.htm">gawk f</a>or windows, then use these one liners<br/> Code: <a>[Select]</a>C:\test>sed -i.bak "/^GOTO/s/PT/-0.7478, 0.0141, 0.6638 PT/" file<br/>PPRINT Vue : second<br/>GOTO / 409.33480, -18.96415, 7.79821 -0.7478, 0.0141, 0.6638 PT 7<br/>GOTO / 419.47490, -24.89781, 19.34762 -0.7478, 0.0141, 0.6638 PT 8<br/><br/>or <br/><br/> Code: <a>[Select]</a>C:\test>gawk "/GOTO/{$5=\"-0.7478, 0.0141, 0.6638 \"$5}1" file<br/>PPRINT Vue : second <br/>GOTO / 409.33480, -18.96415, -0.7478, 0.0141, 0.6638 7.79821 PT 7<br/>GOTO / 419.47490, -24.89781, -0.7478, 0.0141, 0.6638 19.34762 PT 8<br/>Thanks! But that one of my problems! I'm coverting my old Unix Script to DOS! (32bit & 64bit issues) and would like current program to be DOS only! Quote from: graymj on July 31, 2010, 09:22:36 PM</p><blockquote>Thanks! But that one of my problems! I'm coverting my old Unix Script to DOS! (32bit & 64bit issues) and would like current program to be DOS only!<br/></blockquote> <br/>what problem is that ? Most unix tools are <a href="https://interviewquestions.tuteehub.com/tag/already-1974237" style="font-weight:bold;" target="_blank" title="Click to know more about ALREADY">ALREADY</a> ported to <a href="http://gnuwin32.sourceforge.net/packages.html"> GNU win32 packages </a>. you can download them and use it. At least, you don't have to reinvent most of the wheels... 1. Will lines starting PPRINT always have 4 space delimited tokens?<br/><br/> Code: <a>[Select]</a><br/> 1 2 3 4<br/>PPRINT Vue : second<br/><br/><br/><br/>2. Where are you getting those 3 variables to insert? In what form will they be? Do they change each line?<br/><br/>Example of source file below, I extract the variables i want to insert with the<br/>cammand:<br/><br/>FINDSTR /B /N /I /C:"TLAXIS/" %DOSPATH%\%FILE% > vec.txt<br/> for /f "tokens=1-5 <a href="https://interviewquestions.tuteehub.com/tag/delims" style="font-weight:bold;" target="_blank" title="Click to know more about DELIMS">DELIMS</a>= " %%t in (%DOSPATH%\vec.txt) do (<br/> set Y=%%t<br/> echo. Located Vector Value %%u %%v %%w <br/> )<br/><br/>And I only need to insert %%u %%v %%w on lines that start with goto!<br/><br/><br/>PPRINT Vue :<br/>PPRINT MAX FILE SIZE = 90 MEG<br/>PPRINT<br/>PPRINT TLAXIS = AX= -0.7478 AY= 0.0141 AZ= 0.6638<br/>PPRINT TOOL 226109<br/>PPRINT<br/>HEAD/ONE<br/>LOADTL/ 226109<br/>SPINDL/ 800<br/>TLAXIS/ -0.7478, 0.0141, 0.6638<br/>FROM/ .00000, .00000, 1100.00000<br/>RAPID<br/>GOTO / -476.19460, -2.27892, 793.84030 PT 5<br/>RAPID<br/>GOTO / 390.63990, -18.61189, 24.39274 PT 6<br/>FEDRAT/500<br/>GOTO / 409.33480, -18.96415, 7.79821 PT 7<br/>GOTO / 419.47490, -24.89781, 19.34762 PT 8<br/>GOTO / 420.12290, -24.80300, 20.07566 PT 9<br/>GOTO / 420.75380, -24.55062, 20.78100 PT 10Final text file should look like below!<br/>also lines should not exceed 80 char!<br/><br/>PPRINT Vue :<br/>PPRINT MAX FILE SIZE = 90 MEG<br/>PPRINT<br/>PPRINT TLAXIS = AX= -0.7478 AY= 0.0141 AZ= 0.6638<br/>PPRINT TOOL 226109<br/>PPRINT<br/>HEAD/ONE <br/>LOADTL/ 226109<br/>SPINDL/ 800<br/>TLAXIS/ -0.7478, 0.0141, 0.6638<br/>FROM/ .00000, .00000, 1100.00000<br/>RAPID<br/>GOTO / -476.19460, -2.27892, 793.84030 -0.7478, 0.0141, 0.6638 PT 5<br/>RAPID<br/>GOTO / 390.63990, -18.61189, 24.39274 -0.7478, 0.0141, 0.6638 PT 6<br/>FEDRAT/500<br/>GOTO / 409.33480, -18.96415, 7.79821 -0.7478, 0.0141, 0.6638 PT 7<br/>GOTO / 419.47490, -24.89781, 19.34762 -0.7478, 0.0141, 0.6638 PT 8<br/>GOTO / 420.12290, -24.80300, 20.07566 -0.7478, 0.0141, 0.6638 PT 9<br/>GOTO / 420.75380, -24.55062, 20.78100 -0.7478, 0.0141, 0.6638 PT 10</body></html> | |