CMD / Bash/批处理脚本以获取项目/过滤器



例如,我有项目.txt

在项目中.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

在项目2中.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.

最新更新