2015-01-26 27 views
-2

例如,我有items.txtCMD /猛砸/批處理腳本來獲得項目/過濾器

在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 

和他們的價值觀。

+2

您是使用'bash'還是'cmd'?那些是兩個(非常)不同的炮彈。 – bgoldst 2015-01-26 21:57:23

+0

您是否要求某人爲您編程?這是錯誤的網站 - 有很多其他的租用網站編碼器。 – 2015-01-26 22:09:41

+0

我不是在這裏要求某人爲我編程。我已經有了這個代碼FORFILES/p C:\ test \/D -2/S/C「cmd/c echo isdir path」| findstr「test1」> items2.txt – tuturyokgaming 2015-01-26 22:15:04

回答

0

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. 
+0

謝謝你的幫助。 – tuturyokgaming 2015-01-26 23:11:28