Search code examples
windowsunixcmdterminalcut

Corresponding windows cmd command for unix command


I am using following unix command on mac to separate out columns in a file:

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

File sample:

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 

Also below data is junk for me, so i also need to remove it

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

What would be the corresponding windows cmd command to achieve this?


Solution

  • In pure command line syntax

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

    The for /f command reads the input file and each line readed is splitted in the indicated tokens using spaces and tabs as delimiters, storing each of the tokens in a separate replaceable parameter alphabetically consecutive to the indicated starting replaceable parameter (%a in previous code). The code after the do clause is executed for each input line. The full output of the command is filtered with find to only show the required lines.

    The posted code is written to be executed from command line. Inside batch files the percent signs need to be escaped doubling them, so, %a should be %%a, %b should be %%b, ...