954,525 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Parsing text file through a batch

Hey guys,

Hope I'm not posting into the wrong section. I think I have something very simple that i'm having a lot of trouble with. I have a text file called "file.txt"

It contains:
TagString=V3,SCC-COM,WXF1A20V0556,WXE1A2071007,PREBI
TagString=V3,SCC-COM,WXK1A1045668,WXG1A30F3909,POSTBI
TagString=V3,SCC-COM,WMAYP0002467,WMAYP0002769,BI

I want to run a batch file that'll parse the 1st & 2nd token.

So:

for /f "tokens=3,4,5 delims=," %i in (file.txt) do @echo %i %j %k


why won't this work?

Thanks.

Grep
Newbie Poster
21 posts since Jun 2010
Reputation Points: 10
Solved Threads: 0
 

[indent]
What language is that? It doesn't look like a shell script.

In a shell script, parse the file like this:

while IFS== read -r var val
do
   IFS=,
   set -f
   set -- $val
   set +f

   echo "$# tokens"

   token1=$1
   token2=$2
   tokenN=$N
   : etc....
done < file.txt

[/indent]

cfajohnson
Junior Poster
196 posts since Dec 2008
Reputation Points: 25
Solved Threads: 23
 

Looks to me as if poor Grep is stuck in a Microsoft environment. Clue one: he uses 'batch' instead of 'script'. Clue two: "@echo" ... I seem to recall something about a leading '@' in dos batch files. Alas, I no longer remember enough about such things to be helpful.

griswolf
Veteran Poster
1,165 posts since Apr 2010
Reputation Points: 344
Solved Threads: 256
 
Looks to me as if poor Grep is stuck in a Microsoft environment. Clue one: he uses 'batch' instead of 'script'. Clue two: "@echo" ... I seem to recall something about a leading '@' in dos batch files. Alas, I no longer remember enough about such things to be helpful.

Yes, after reading the first response i was like ah crap, posted in the wrong section =/
I got it figured out though. Thanks.

Grep
Newbie Poster
21 posts since Jun 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You