1.

Solve : Dos String Search & Replace Columns?

Answer»

HI 
QUESTION, is it possible to do the following example with batch file commands?

Replace all lines that start with GOTO in a file starting with column 43 to 71 that CONTAINS spaces with three variables %%u %%v %%w
(-0.7478,  0.0141,  0.6638) then add BALANCE of line (PT     7) for example below!


Example;

                    FROM
PPRINT  Vue      : second
GOTO  /  409.33480,  -18.96415,    7.79821                              PT     7
GOTO  /  419.47490,  -24.89781,   19.34762                              PT     8

                    TO
PPRINT  Vue      : second
GOTO  /  409.33480,  -18.96415,    7.79821   -0.7478,  0.0141,  0.6638  PT     7
GOTO  /  419.47490,  -24.89781,   19.34762   -0.7478,  0.0141,  0.6638  PT     8you can download sed or gawk for windows,  then use these one liners
Code: [Select]C:\test>sed -i.bak "/^GOTO/s/PT/-0.7478,  0.0141,  0.6638  PT/" file
PPRINT  Vue      : second
GOTO  /  409.33480,  -18.96415,    7.79821                              -0.7478,  0.0141,  0.6638  PT     7
GOTO  /  419.47490,  -24.89781,   19.34762                              -0.7478,  0.0141,  0.6638  PT     8

or

Code: [Select]C:\test>gawk "/GOTO/{$5=\"-0.7478,  0.0141,  0.6638 \"$5}1" file
PPRINT Vue : second
GOTO / 409.33480, -18.96415, -0.7478,  0.0141,  0.6638 7.79821 PT 7
GOTO / 419.47490, -24.89781, -0.7478,  0.0141,  0.6638 19.34762 PT 8
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

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!

what problem is that ? Most unix tools are ALREADY ported to GNU win32 packages . 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?

Code: [Select]
   1     2       3   4
PPRINT  Vue      : second



2. Where are you getting those 3 variables to insert? In what form will they be? Do they change each line?

Example of source file below, I extract the variables i want to insert with the
cammand:

FINDSTR /B /N /I /C:"TLAXIS/" %DOSPATH%\%FILE% > vec.txt
  for /f "tokens=1-5 DELIMS= " %%t in (%DOSPATH%\vec.txt) do (
  set Y=%%t
   echo. Located Vector Value   %%u %%v %%w
      )

And I only need to insert %%u %%v %%w  on lines that start with goto!


PPRINT  Vue      :
PPRINT                MAX FILE SIZE = 90 MEG
PPRINT
PPRINT TLAXIS = AX= -0.7478     AY= 0.0141     AZ= 0.6638
PPRINT TOOL 226109
PPRINT
HEAD/ONE
LOADTL/ 226109
SPINDL/ 800
TLAXIS/ -0.7478,      0.0141,        0.6638
FROM/   .00000,      .00000,      1100.00000
RAPID
GOTO  / -476.19460,   -2.27892,  793.84030                              PT     5
RAPID
GOTO  /  390.63990,  -18.61189,   24.39274                              PT     6
FEDRAT/500
GOTO  /  409.33480,  -18.96415,    7.79821                              PT     7
GOTO  /  419.47490,  -24.89781,   19.34762                              PT     8
GOTO  /  420.12290,  -24.80300,   20.07566                              PT     9
GOTO  /  420.75380,  -24.55062,   20.78100                              PT    10Final text file should look like below!
also lines should not exceed 80 char!

PPRINT  Vue      :
PPRINT                MAX FILE SIZE = 90 MEG
PPRINT
PPRINT TLAXIS = AX= -0.7478     AY= 0.0141     AZ= 0.6638
PPRINT TOOL 226109
PPRINT
HEAD/ONE                                                               
LOADTL/ 226109
SPINDL/ 800
TLAXIS/ -0.7478,      0.0141,        0.6638
FROM/   .00000,      .00000,      1100.00000
RAPID
GOTO  / -476.19460,   -2.27892,  793.84030   -0.7478,   0.0141,  0.6638 PT     5
RAPID
GOTO  /  390.63990,  -18.61189,   24.39274   -0.7478,   0.0141,  0.6638 PT     6
FEDRAT/500
GOTO  /  409.33480,  -18.96415,    7.79821   -0.7478,   0.0141,  0.6638 PT     7
GOTO  /  419.47490,  -24.89781,   19.34762   -0.7478,   0.0141,  0.6638 PT     8
GOTO  /  420.12290,  -24.80300,   20.07566   -0.7478,   0.0141,  0.6638 PT     9
GOTO  /  420.75380,  -24.55062,   20.78100   -0.7478,   0.0141,  0.6638 PT    10


Discussion

No Comment Found