Windows – how to use dos commands to do following

doswindows

At the following location
\ncsusnasent02.na.jnj.com\its_diq_na_win_dev\PowerCenter\infa_shared\WCPIT_BIO_EDW\SrcFiles\DDDMD\DDD.CLI026.WK0933.DDDMR45.001.head

I have one file
DDD.CLI026.WK0933.DDDMR45.001.head

if i open this file
i get data as following(in a single line)

HEADER0101IMS HEALTHDMD Weekly   D        DD.CLI026.WK0933.DDDMR45         Centocor    DMDDRM45               W2009080210120090831125325ssnyder@us.imshealth.com      
    TRAIL0101 000000000581                         0000000000CKSUM000002236804730

we need to copy 581(it will not be same always it gets updated everyday) from this file

and put it in a variable

Best Answer

you can try the below. It will set the field into the environment variable id:

 for /f "tokens=10" %%a IN (%1) do (
   SET id=%%a
 )
 echo %id%

You can pass the full path and file name into the bat as the first argument.

edit:

This simple bat will take the input from the file you specify on the commandline (param %1), it will use the default separators of <space> and <tab> to break the line in your file - defined in the IN set - into a set of tokens. The "tokens=10" param tells the processor to pass the 10th token, which turns out to be your number in question, into the DO block. It is passed in as a param %%a. Within the DO block, I simply assign that value to an environment variable id. After the for command is complete, I echo the value out to the console.