我在批处理脚本中写了一段代码,有点像:
(
wmic.exe /node:x.x.x.x computersystem get name
wmic.exe /node:x.x.x.x computersystem get domain
wmic.exe /node:x.x.x.x computersystem get manufacturer
wmic.exe /node:x.x.x.x computersystem get model
wmic.exe /node:x.x.x.x computersystem get username
wmic.exe /node:x.x.x.x computersystem get systemtype
) >> file.txt
的内容file.txt
包括:
ABC123
xyz.com
Hewlett-Packard
HP xw4400 Workstation
ABC123\Administrator
x64-based PC
我希望将以上信息存储为 CSV 格式,如下所示:
ABC123 , xyz.com , Hewlett-Packard , HP xw4400 Workstation , ABC123\Administrator , x64-based PC
如何实现这一点?
答案1
插入回声wmic 调用之间的语句。
答案2
echo -n # -n 不输出尾随的换行符
忘记 echo,使用带有分隔符换行符 -d'\n' 的 printf 和 xarg
$ cat file.txt
ABC123
xyz.com
Hewlett-Packard
HP xw4400 Workstation
ABC123\Administrator
x64-based PC
$ cat file.txt | xargs -d'\n' printf "%s , %s , %s , %s , %s , %s \n"
ABC123 , xyz.com , Hewlett-Packard , HP xw4400 Workstation , ABC123\Administrator , x64-based PC