tags:

views:

196

answers:

3

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               [email protected]      
    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

+3  A: 

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.

akf
@akf.......i have not understood wat u have done
Irveen
A: 

Take a look at the FOR command, specifically the part about the /F parameter.

I'm not certain enough about the structure of that line to even try to write the full command, but you should be able to write it yourself given that information.

Michael Madsen
A: 

Hmm to me it looks more like the guy needs a dos substr... i.e.

@Echo Off

If not %1.==[]. (Cmd /V:On /C Call %0 [] %1 & GoTo :EOF)

Shift
Set MyVariable=HELLOWORLD
Set ASubStr=!MyVariable:~%1!
Echo [!ASubStr!]

So for example save this as test.bat and then call "test.bat 5" and it will echo WORLD

Google DOS Substring and work out how to parse your text variable the way you want it.

Julian Young
na na na..............nt the required ans
Irveen