batch-file - 如何将多管道命令的输出分配给 Windows CMD 批处理中的变量?
问题描述
我需要遍历目录中的一组文件,匹配通配符模式并在其他两个模式之间提取文件名的一部分。Unix(即 bash)等效命令将是这样的:
ls -1 "$wildcard1"*"$wildcard2" | while read filename; do
string2find=`echo $filename | cut -d $delim1 -f2 | cut -d $delim2 -f1`
echo $string2find
#do something with string2find variable here
done
在批处理文件中,我尝试了这个
for %%f in (WILD1*WILD2) do (
echo %%f | cut -d_ -f2 | cut -d"." -f1> temp.out <--here, need something between an "_" and a "."
type temp.out <-- see the right string in the file
set var= <clear the variable
set /p var=<temp.out
echo %var% <-- ECHO is off message I am getting here
del temp.out
REM need to do something with var here
)
我能找到的所有示例都没有管道命令。
解决方案
推荐阅读
- javascript - 内容可编辑的正则表达式空格不起作用
- c# - 如何从 azure 函数执行我的 docker 容器
- c - 使用字节数组我得到一个“从 char* 到字节的无效转换”
- java - 没有使用 JUnit @Rule 删除 TemporaryFolder
- html - 通过 CSS 替换图像
- jquery - 如何用 jquery html(String) 替换 .innerHTML(String)?
- jenkins - 在 GitHub 拉取请求页面上添加一个按钮以手动触发 Jenkins 作业
- python - 使用 pymongo 从集合中获取 Mongo 字段名称
- python - 关于网页抓取的问题 - 与 Discord
- python - 向 Kivy.app.on_start 函数发送参数