-2

在以下位置 \ncsusnasent02.na.jnj.com\its_diq_na_win_dev\PowerCenter\infa_shared\WCPIT_BIO_EDW\SrcFiles\DDDMD\DDD.CLI026.WK0933.DDDMR45.001.head

我有一个文件 DDD.CLI026.WK0933.DDDMR45.001.head

如果我打开这个文件,我会得到如下数据(单行)

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

我们需要从这个文件中复制 581(它不会总是每天更新)

并将其放入变量中

4

3 回答 3

3

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.

于 2009-09-14T12:55:07.847 回答
0

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.

于 2009-09-14T12:55:51.213 回答
0

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.

于 2009-09-14T12:59:19.890 回答