Windows command for cutting columns from a text

不问归期 提交于 2019-11-30 04:29:09

问题


The following content is stored in a file:

chrome.exe                   512 Console                 0     73,780 K
chrome.exe                   800 Console                 0     11,052 K
chrome.exe                  1488 Console                 0     92,720 K
chrome.exe                  1600 Console                 0     32,344 K
chrome.exe                  2240 Console                 0     35,132 K
chrome.exe                  2360 Console                 0     21,276 K
chrome.exe                  3524 Console                 0     66,732 K
chrome.exe                  3924 Console                 0     23,524 K

Is there a way to extract the 5th column with the Windows command line?

Something like the UNIX cut command.


回答1:


for /f "tokens=5 delims= " %i in (file.txt) DO echo %i




回答2:


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




回答3:


@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).




回答4:


If you had perl installed:

perl.exe -na  -e "print qq{$F[4]\n}" < myfile.txt


来源:https://stackoverflow.com/questions/4441827/windows-command-for-cutting-columns-from-a-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!