我该如何应用呢? [英] How do I apply this?

查看:77
本文介绍了我该如何应用呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将其用作下面代码的变量,而不是1.txt中ClassName =之后的内容,我想在此之间使用什么内容:

I would like to use as the variable for my code below, instead of what comes after ClassName= in 1.txt, I would like what comes in-between this:

EntryText =船沉没了!|网格AO 77 | 变量

EntryText=Ship sunk!|Grid AO 77|Variable,

(请注意变量后的逗号和其前的|)

(notice the comma after the variable and the | before it )

因此,在第二行结束的文本行之后抓取|并且在逗号之前.

So grab after the text line ending with the second | and before the comma.

变量之前的文本行将是相同且恒定的,除了"Grid"之后是常数,直到第二个||

The text line before the variable will be the same and constant EXCEPT after "Grid" there could be any mixture of letters and numbers up until the second |

因此,我尝试使用介于两者之间的变量:

So I am trying to use as a variable, what is in between:

EntryText =船沉没了!|网格(任何字母或数字的组合) | (变量)(逗号)

EntryText=Ship sunk!|Grid (Any combination of letters or numbers) | (variable) , (comma)

因此在第二个之间抓紧|和逗号.比你. 我想将ClassName =之后的变量捕获替换为第二个|之间的变量.和逗号. 请记住,还有其他|和我不想抓取的文件中的逗号,我只想在|之后抓取变量并且在逗号之前,如果它在"EntryText = Ship沉没了!| Grid ....

So grab in between the second | and the comma. Than you. I would like to replace the grabbing of the variable after ClassName= to what is in between the second | and the comma. Please keep in mind that there are other | and commas in the file that I don't want to grab, I just want to grab the variable after | and before comma if its after the "EntryText=Ship sunk!|Grid ....

再次,我不要网格部分,我想在第二个|并且在逗号之前.还将有许多EntryText行,因此我想抓住其中的所有部分并放入我的代码中.

Again, I don't want the Grid part, I'd like what comes after the second | and before the comma. There will be many EntryText lines as well, so I'd like to grab that part of all of them and put in my code.

因此,我要复制上面列出的变量的位置,而不是在ClassName =之后.

So instead of what is after ClassName=, I'd like to copy what is where the variable listed above.

谢谢您的时间!

@echo off

copy 2.txt 2.txt-backup

setlocal enableDelayedExpansion

>2.txt (
for /f "tokens=1* delims=:" %%A in ('findstr /n "^" 2.txt-backup') do (
( echo !ln!| findstr "^Type=206$" >NUL && set ln=ln ) || (
    set "ln=%%B"
    if "!ln:~0,6!"=="Class=" (
        findstr /c:"ClassName=!ln:~6!" "E:\Dropbox\New folder\Log_*.txt" >"E:\Dropbox\New folder\null" && (
            echo Class=ShipDummy
            set "ln=Type=206"
        )
    )
    if #!ln!==# (echo;) else echo !ln!
)
)
)

有人给了我这个底部代码,但是我不知道它是我想要的还是如何应用于上面的代码:

I was given this bottom code by someone, but I don't know if its what I want or how to apply it to the above:

for /f "tokens=3 delims=|" %%C in ("%%B") do for /f "tokens=1 delims=," %%D in ("%%C") do echo %%D

谢谢!!!!!

推荐答案

我认为您想要这样的东西...

I think you want something like this...

...
set "ln=%%B"
for /f "tokens=3 delims=|" %%C in ("%%B") do for /f "tokens=1 delims=," %%D in ("%%C") do set "MyVar=%%D"
findstr /c:"ClassName=!MyVar!" "E:\Dropbox\New folder\Log_*.txt" >"E:\Dropbox\New folder\null" && (
    echo Class=ShipDummy
    ...

这篇关于我该如何应用呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆