Windows command for cutting columns from a text

后端 未结 4 539
温柔的废话
温柔的废话 2021-01-05 07:34

The following content is stored in a file:

chrome.exe                   512 Console                 0     73,780 K
chrome.exe                   800 Console           


        
相关标签:
4条回答
  • 2021-01-05 07:36
    @ECHO OFF
    
    for /F "tokens=2-4" %%a in (%1) DO ( echo %%a %%b %%c )
    

    took me a long time to find out that %%a %%b %%c .... [%%z] refer to subsequent colums in a text file. So this example will extract the 2nd, 3rd and 4th column (word) from a textfile (%1).

    0 讨论(0)
  • 2021-01-05 07:46

    Use double % in variable

    for /f "tokens=5 delims= " %%i in (file.txt) DO echo %%i
    
    0 讨论(0)
  • 2021-01-05 07:47

    If you're familiar with the GNU cut utility, you might be better off using the Win32 port:

    http://gnuwin32.sourceforge.net/packages/coreutils.htm

    0 讨论(0)
  • 2021-01-05 07:52

    If you had perl installed:

    perl.exe -na  -e "print qq{$F[4]\n}" < myfile.txt
    
    0 讨论(0)
提交回复
热议问题