Page 1 of 1

String Manipulation with Output of FINDSTR

Posted: 16 Sep 2009 22:02
by brydhenn
Hi,

I'm parsing this kind of file
Wings\IDSS_SAR_Wings_rev2.bdf:CBEAM 10063579120000601003334410047685 0. -1. 0.
Wings\Rigids_SAR_ATD_Snubbers_V2.bdf:RBE2 1010000010053768 123456 202383 202427 202429 202470 202478+
Wings\Rigids_SAR_ATD_Snubbers_V2.bdf:CBUSH,10100111,10100100,11000011,10033349,,,,0
Beams\ATDs_rev3.bdf:RBE2 1010000411000009 123456 116283 116284 117263 117264 117265+

with this commandline FOR /F " tokens=1,2,3* delims=,: " %i IN ('type C:\_Consulting\RCM\PhaseB\Models\Master_Model\TempElms.txt') DO echo.%i %k:~0,8%

The issue I have is that %k is always the same. It takes the last line value and echos it for each line. I have no clue what to change.

OUTPUT
Wings\IDSS_SAR_Wings_rev2.bdf 10100015
Wings\Rigids_SAR_ATD_Snubbers_V2.bdf 10100015
Wings\Rigids_SAR_ATD_Snubbers_V2.bdf 10100015
Beams\ATDs_rev3.bdf 10100015

Any help would be appreciated,
Thanks,

Posted: 17 Sep 2009 09:01
by avery_larry
substrings don't work with the %%n in a for loop. You have to assign it to a variable and then do substring manipulation on that variable like this:


Code: Select all

setlocal enabledelayedexpansion
FOR /F "usebackq tokens=1,2,3* delims=,: " %%i IN ("c:\_Consulting\RCM\PhaseB\Models\Master_Model\TempElms.txt") DO (
   set "tmpvar=%%k"
   echo.%%i !tmpvar:~0,8!
)

Posted: 20 Sep 2009 20:07
by ghostmachine4
if you can download gawk for windows, here's a one liner

Code: Select all

C:\test>gawk "BEGIN{FS=\"[:, ]\"}{print $1,substr($3,1,8)}" file
Wings\IDSS_SAR_Wings_rev2.bdf 10063579
Wings\Rigids_SAR_ATD_Snubbers_V2.bdf 10100000
Wings\Rigids_SAR_ATD_Snubbers_V2.bdf 10100111
Beams\ATDs_rev3.bdf 10100004