2015-09-30 115 views
-1

我在Mac上使用以下UNIX命令分離出列在文件中:相應的Windows cmd命令

cut -d ' ' -f 3,4,5,10,11,12 < testFile.txt 

文件樣本:

unzip trace file: 
Archive: /Logs/1.trace/instrument_data/2DFBB7CF-2B32-41D6-9FA6-73CF813DFC24/run_data/1.run.zip 
    inflating: Logs/2.trace/instrument_data/2DFBB7CF-2B32-41D6-9FA6-73CF813DFC24/run_data/1.run 


Run 1, starting at 2015/08/06 16:46:35:185, running until 2015/08/06 16:53:30:445 
Sample 0: CPU Usage: 2.56% Memory Usage: 5608.00 KiB Timestamp: 2015/08/06 16:46:35:955 
Sample 1: CPU Usage: 1.21% Memory Usage: 5576.00 KiB Timestamp: 2015/08/06 16:46:37:143 
Sample 2: CPU Usage: 2.46% Memory Usage: 5560.00 KiB Timestamp: 2015/08/06 16:46:38:323 
Sample 3: CPU Usage: 2.49% Memory Usage: 5560.00 KiB Timestamp: 2015/08/06 16:46:39:502 
Sample 4: CPU Usage: 2.51% Memory Usage: 5560.00 KiB Timestamp: 2015/08/06 16:46:40:674 
Sample 5: CPU Usage: 2.56% Memory Usage: 5560.00 KiB Timestamp: 2015/08/06 16:46:41:832 
Sample 6: CPU Usage: 2.21% Memory Usage: 5560.00 KiB Timestamp: 2015/08/06 16:46:43:009 
Sample 7: CPU Usage: 1.92% Memory Usage: 5560.00 KiB Timestamp: 2015/08/06 16:46:44:202 
Sample 8: CPU Usage: 2.83% Memory Usage: 5572.00 KiB Timestamp: 2015/08/06 16:46:45:408 

而且下面的數據是垃圾,我,所以我也需要刪除它

unzip trace file: 
    Archive: /Logs/1.trace/instrument_data/2DFBB7CF-2B32-41D6-9FA6-73CF813DFC24/run_data/1.run.zip 
     inflating: Logs/2.trace/instrument_data/2DFBB7CF-2B32-41D6-9FA6-73CF813DFC24/run_data/1.run 

什麼是將相應的Windows CMD命令來實現這一目標?

回答

1

在純命令行語法

(for /f "tokens=3-5,10-12" %a in (testfile.txt) do @echo %a %b %c %d %e %f)|find "CPU" 

for /f命令讀取輸入文件和readed使用空格和製表符分隔符所指示的標記被分裂的每一行中,每個令牌存儲在一個單獨的可替換參數與指示的起始可替換參數(前面的代碼中的%a)按字母順序相連。對每條輸入行執行do子句之後的代碼。該命令的完整輸出用find進行過濾,僅顯示所需的行。

發佈的代碼被寫入從命令行執行。在批處理文件中,百分號需要將其加倍,因此,%a應該是%%a,%b應該是%%b,...