URGENT: Parsing a line using Batch
Posted: 25 Oct 2009 01:23
Hi,
For some reason the requirement is BATCH scripting from the client. I am a beginner in Batch scripting but managed to write the piece of code to automate some stuff. I am struck with some 3 simply issues. I am not able to figure out even on googling.
Hence requesting your help here to fix the same
1. I have saved one XML as a txt file and processing the same. Below are 2 sample piece of code.
<message field1="10" field2="Title" Field3="My description for this" Field4="0" Filed5="60" Filed6="20” />
<message field1="11" field2="hello" Field3="damn difficult" Field4="1" Filed5="0" Filed6="0” />
Let us assume only 1st line(highlighted in Bold) is there in my TXT file. I need to collect
• Field4=”0” into a variable called Var
• Field5=”60” into a variable called Var1
How can I do that? I am not very sure how to process a line and pick up a string into a variable
2. Say a variable v1=”123456 ”
I am able to check the 8th bit as blank with the code below %v1:~7,1%
IF %var:~7,1%==" " echo blank
But I wanted to check if the 8th bit is equal to “. It looks like the Double quote is a special character and hence the screen just finishes the execution. It doesn’t do as intended. I tried something like this
IF %var:~8,1%==" echo blank ------ Doesn’t work
IF “%var:~8,1%”==" echo blank ------- Doesn’t work
IF %var:~8,1%==\" echo blank ------- to remove some special meaning etc
3. How to check if a string is a Numeric or not? I wanted only the numeric to validate something.
Thanks in advance
Regards
Kamath
For some reason the requirement is BATCH scripting from the client. I am a beginner in Batch scripting but managed to write the piece of code to automate some stuff. I am struck with some 3 simply issues. I am not able to figure out even on googling.
Hence requesting your help here to fix the same
1. I have saved one XML as a txt file and processing the same. Below are 2 sample piece of code.
<message field1="10" field2="Title" Field3="My description for this" Field4="0" Filed5="60" Filed6="20” />
<message field1="11" field2="hello" Field3="damn difficult" Field4="1" Filed5="0" Filed6="0” />
Let us assume only 1st line(highlighted in Bold) is there in my TXT file. I need to collect
• Field4=”0” into a variable called Var
• Field5=”60” into a variable called Var1
How can I do that? I am not very sure how to process a line and pick up a string into a variable
2. Say a variable v1=”123456 ”
I am able to check the 8th bit as blank with the code below %v1:~7,1%
IF %var:~7,1%==" " echo blank
But I wanted to check if the 8th bit is equal to “. It looks like the Double quote is a special character and hence the screen just finishes the execution. It doesn’t do as intended. I tried something like this
IF %var:~8,1%==" echo blank ------ Doesn’t work
IF “%var:~8,1%”==" echo blank ------- Doesn’t work
IF %var:~8,1%==\" echo blank ------- to remove some special meaning etc
3. How to check if a string is a Numeric or not? I wanted only the numeric to validate something.
Thanks in advance
Regards
Kamath