No announcement yet.

URGENT: Need help on Batch file.

  • Filter
  • Time
  • Show
Clear All
new posts

  • URGENT: Need help on Batch file.

    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


  • #2
    Re: URGENT: Need help on Batch file.

    Try this

    @echo off
    for /f "tokens=2 delims=><" %%a in ('type file.xml ^| find

    "<Filed5>"') do set F5=%%a
    echo The Filed5 is %F5%

    You can develop and use further


    • #3
      Re: URGENT: Need help on Batch file.

      I understand the requirement is in batch, but it can severely limit you. Any scripting language will offer a lot more benefit. Here are the answers.

      1. Extracting Field4 and Field5 values into Var and Var1.

      # Read file in.
      var str file, Var, Var1 ; cat "x.txt" >$file
      stex -c "^Field4=\"^]" $file > null ; stex -c "]^\"^" $file > $Var
      stex -c "^Field5=\"^]" $file > null ; stex -c "]^\"^" $file > $Var1
      echo $Var $Var1
      2. Check if 8th digit of variable v1 is double quote.

      (I think you mean 8th digit, not 8th bit.)

      if ( { chex "8" $v1 } == "\"" )
          echo "8th digit of v1 is double quote."
      3. Usage of double quote in string constants.

      Escape it with backslash, as, \".

      Both above codes show that.

      The above code fragments are in biterscripting. But any scripting language will do. biterscripting probably comes closest the native unix and linux scripting. You can call the scripts from DOS batch as follows.

      biterscripting.exe scriptfile.txt
      The commands I used are stex=string extractor and chex=character extractor. Their help pages are at http: //www .biterscripting .com/helppages/stex.html and http: //www .biterscripting .com/helppages/chex.html.

      Last edited by Rems; 29th June 2010, 18:20. Reason: live urls removed by mod


      • #4
        Re: URGENT: Need help on Batch file.

        1st of all my sincere thanks to you for replying to my query. I think I have almost resolved this issue. I use a combination of few stufff.....Because of time crunch I am not able to dump the code now in this forum...

        Once I complete I will post How is that i could do it. Then we can have some further discussion.

        Thanks once again