我想知道是否有一行代码可以在Windows上执行以下操作:
myCommand options1 | cut -c 10-20 > temp1.txt
myCommand options2 | cut -c 10-20 > temp2.txt
paste temp1.txt temp2.txt
我也想使用diff
而不是paste
做类似的事情,但我猜答案是一样的(是的? 通常,temp1 和 2 都有多行文本。 我发现以下内容看起来像一个类似的问题 在 excel 文件中的两列中打印两个命令的输出 但这没有答案。
编辑/更新:我现在意识到我对"单行"不是很清楚。 显然,我可以通过简单地用 & 符号分隔它们来将所有三行放在一条线上。 这不是我要找的。 我依稀记得多年前使用Unix时,反引号可以用于这样的事情。 也许像
paste `cmd1` `cmd2`
不太确定(? 这就是我正在寻找的东西(在窗户上(。理想情况下,它不会比简单地输入上面的三行涉及(太多(更多的输入。 这存在吗?
我永远不会明白为什么人们想要使用单行,但你来了:
(ping localhost |find "Mini" & ipconfig |find "IPv4")>temp.txt
编辑以并排显示两个命令的输出:
@echo off
setlocal enabledelayedexpansion
ping localhost |find "TTL" >1.txt
ipconfig |find ":" >2.txt
<1.txt (
for /f "delims=" %%a in (2.txt) do (
set /p "x="
echo !x! ; %%a
set "x=-"
)
)>temp1.txt
与单行相同(作为批处理文件(:
cmd /v:on /c ping localhost |find "TTL" >1.txt & ipconfig |find ":" >2.txt & <1.txt (for /f "delims=" %%a in (2.txt) do (set /p "x=" & echo !x! ; %%a & set "x=-"))>temp2.txt
在命令行上使用的单行代码:
cmd /v:on /c "ping localhost |find "TTL" >1.txt & ipconfig |find ":" >2.txt & <1.txt (for /f "delims=" %a in (2.txt) do @(set /p "x=" & echo !x! ; %a & set "x=-"))>temp.txt"
注意:结果中的行数与2.txt
中的行数一样多(第二个命令的输出(。如果1.txt
有更多的行,则省略它们(更少的行不是问题(