使用标准 Windows 命令行/批处理命令模拟 unix 'cut'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/98363/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 11:14:45  来源:igfitidea点击:

emulate unix 'cut' using standard windows command line/batch commands

windowsunixcommand-line

提问by Kevin Haines

Is there a way to emulate the unix cut command on windows XP, without resorting to cygwin or other non-standard windows capabilities?

有没有办法在 Windows XP 上模拟 unix cut 命令,而无需求助于 cygwin 或其他非标准的 Windows 功能?

Example: Use tasklist /v, find the specific task by the window title, then extract the PID from that list to pass to taskkill.

示例:使用 tasklist /v,通过窗口标题找到特定任务,然后从该列表中提取 PID 传递给 taskkill。

回答by Wedge

FYI, tasklist and taskkill already have filtering capabilities:

仅供参考,tasklist 和 taskkill 已经具有过滤功能:

tasklist /FI "imagename eq chrome.exe"
taskkill /F /FI "imagename eq iexplore.exe"

If you want more general functionality, batch scripts (ugh) can help. For example:

如果您想要更通用的功能,批处理脚本(呃)可以提供帮助。例如:

for /f "tokens=1,2 delims= " %%i in ('tasklist /v') do (
  if "%%i" == "%~1" (
    echo TASKKILL /PID %%j
  )
)

There's a fair amount of help for the windows command-line. Type "help" to get a list of commands with a simple summary then type "help " for more information about that command (e.g. "help for").

Windows 命令行有很多帮助。键入“help”以获取带有简单摘要的命令列表,然后键入“help”以获取有关该命令的更多信息(例如“help for”)。