CMD/Bash/Batch 获取 item/filters 的脚本

CMD/Bash/Batch Script to get item/filters

比如我有items.txt

在items.txt

有多行

test1=import1
test1=import2
test2=import1
test1=import3
test2=import4
test3=import2
test3=import2
test1=import1
test1=import2
test2=import1
test1=import3
test2=import4
test3=import2
test3=import2
test1=import1
test1=import2
test2=import1
test1=import3
test2=import4
test3=import2
test3=import2
test1=import1
test1=import2
test2=import1
test1=import3
test2=import4
test3=import2
test3=import2
test1=import1
test1=import2
test2=import1
test1=import3
test2=import4
test3=import2
test3=import2

我需要做的是从 test1、test2、test3 或每个项目等中获取至少 1 个值。并将其传递给另一个文本文件 --> items2.txt

并在 items2.txt

应该是这样的

test1 
test2
test3 

和他们的价值观。

ForFiles 文件不是文本行。

使用 For,它处理文件、文本行、命令输出以及其他一些事情。

for /f "tokens=1 delims==" %A in (c:\somefile.txt) do echo %A

先取文本 = 在文件中的一行文本中签名。

重定向将屏幕输出写入文件。所以这会将它写入文件。

for /f "tokens=1 delims==" %A in (c:\somefile.txt) do echo %A >>Output.txt

这里是 cmd 中字符的快速参考。

&    seperates commands on a line.

&&    executes this command only if previous command's errorlevel is 0.

||    (not used above) executes this command only if previous command's errorlevel is NOT 0

>    output to a file

>>    append output to a file

<    input from a file

|    output of one command into the input of another command

^    escapes any of the above, including itself, if needed to be passed to a program

"    parameters with spaces must be enclosed in quotes

+ used with copy to concatinate files. E.G. copy file1+file2 newfile

, used with copy to indicate missing parameters. This updates the files modified date. E.G. copy /b file1,,

%variablename% a inbuilt or user set environmental variable

!variablename! a user set environmental variable expanded at execution time, turned with SelLocal EnableDelayedExpansion command

%<number> (%1) the nth command line parameter passed to a batch file. %0 is the batchfile's name.

%* (%*) the entire command line.

%<a letter> or %%<a letter> (%A or %%A) the variable in a for loop. Single % sign at command prompt and double % sign in a batch file.