String Manipulation with Output of FINDSTR

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
brydhenn
Posts: 1
Joined: 16 Sep 2009 21:18

String Manipulation with Output of FINDSTR

#1 Post by brydhenn » 16 Sep 2009 22:02

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,

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#2 Post by avery_larry » 17 Sep 2009 09:01

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!
)

ghostmachine4
Posts: 319
Joined: 12 May 2006 01:13

#3 Post by ghostmachine4 » 20 Sep 2009 20:07

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

Post Reply