简体   繁体   English

批处理文件 - 如何读取由空格分隔的字符串的第一个标记

[英]Batch file - how to read first token of a string delimited by a space

Using batch script, I want to get a first token of a line delimited by a space. 使用批处理脚本,我想得到一个由空格分隔的行的第一个标记。 Can this be done without a for loop? 这可以在没有for循环的情况下完成吗?

example input: a b c d
example output: a

Thanks. 谢谢。

Pass the text as a batch parameter using CALL command like this: 使用CALL命令将文本作为批处理参数传递,如下所示:

@echo off
setlocal
set text=a b c d
set result=
call :getFirstParam %text%
echo %result%
goto :eof
:getFirstParam
set result=%1
goto :eof

您可以这样使用AWK:

awk '{print $1}' <your_file>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM