用于从文本中剪切列的 Windows 命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4441827/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Windows command for cutting columns from a text
提问by Vineel Kumar Reddy
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?
有没有办法用 Windows 命令行提取第 5 列?
Something like the UNIX cut
command.
类似于 UNIXcut
命令。
回答by Sanjit Saluja
for /f "tokens=5 delims= " %i in (file.txt) DO echo %i
for /f "tokens=5 delims=" %i in (file.txt) DO echo %i
回答by bcosca
If you're familiar with the GNU cut utility, you might be better off using the Win32 port:
如果您熟悉 GNU cut 实用程序,则最好使用 Win32 端口:
回答by missing awk
@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).
我花了很长时间才发现%%a %%b %%c .... [%%z]
引用文本文件中的后续列。因此,此示例将从文本文件 (%1) 中提取第 2、第 3 和第 4 列(单词)。
回答by knb
If you had perl installed:
如果你安装了 perl:
perl.exe -na -e "print qq{$F[4]\n}" < myfile.txt