2

需要帮助找到一些用于 bat 文件的命令/工具以自动转换内容:

%PCI\VEN_1B21&DEV_0601.DeviceDesc%= asahci_Inst, PCI\VEN_1B21&DEV_0601
%PCI\VEN_1B21&DEV_0602.DeviceDesc%= asahci_Inst, PCI\VEN_1B21&DEV_0602
%PCI\VEN_1B21&DEV_0611.DeviceDesc%= asahci_Inst, PCI\VEN_1B21&DEV_0611
%PCI\VEN_1B21&DEV_0612.DeviceDesc%= asahci_Inst, PCI\VEN_1B21&DEV_0612

为此(清理):

VEN_1B21&DEV_0601
VEN_1B21&DEV_0602
VEN_1B21&DEV_0611
VEN_1B21&DEV_0612

为此(插入代码和下一行):

devcon find * | find /i "VEN_1B21&DEV_0601" >NUL 
if /i %ERRORLEVEL% equ 0 set DEVICE=DETECTED
devcon find * | find /i "VEN_1B21&DEV_0602" >NUL
if /i %ERRORLEVEL% equ 0 set DEVICE=DETECTED
devcon find * | find /i "VEN_1B21&DEV_0611" >NUL
if /i %ERRORLEVEL% equ 0 set DEVICE=DETECTED
devcon find * | find /i "VEN_1B21&DEV_0612" >NUL
if /i %ERRORLEVEL% equ 0 set DEVICE=DETECTED

我已经尝试过各种工具,如 rxfind(零文档)和 sed,但我认为我用错了。

4

2 回答 2

1

使用 sed:

pre='devcon find * | find \/i "'
post='" >NUL\nif \/i %ERRORLEVEL% equ 0 set DEVICE=DETECTED'
sed -n "s/.*\\\\\(.*\)/$pre\\1$post/p" input

或者:

sed 's/.*\\\(.*\)/devcon find * | find \/i "\1" >NUL\nif \/i %ERRORLEVEL% equ 0 set DEVICE=DETECTED/' input
于 2012-12-11T04:06:42.050 回答
0

You could also use awk:

awk -F '\' -v a="devcon find * | find /i" -v b=">NUL\nif /i %ERRORLEVEL% equ 0 set DEVICE=DETECTED" '{ print a, "\""$NF"\"", b }' file

or:

awk -F '\' '{ printf "devcon find * | find /i \"%s\" >NUL\nif /i %%ERRORLEVEL%% equ 0 set DEVICE=DETECTED\n", $NF }' file

Results:

devcon find * | find /i "VEN_1B21&DEV_0601" >NUL
if /i %ERRORLEVEL% equ 0 set DEVICE=DETECTED
devcon find * | find /i "VEN_1B21&DEV_0602" >NUL
if /i %ERRORLEVEL% equ 0 set DEVICE=DETECTED
devcon find * | find /i "VEN_1B21&DEV_0611" >NUL
if /i %ERRORLEVEL% equ 0 set DEVICE=DETECTED
devcon find * | find /i "VEN_1B21&DEV_0612" >NUL
if /i %ERRORLEVEL% equ 0 set DEVICE=DETECTED
于 2012-12-11T04:28:49.570 回答