China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-24 02:39
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] Extract characters with similar formats in the file [a bit difficult, not seen in the forum] View 2,520 Replies 23
Floor 16 Posted 2007-06-04 22:37 ·  中国 湖南 永州 电信
初级用户
Credits 68
Posts 32
Joined 2006-10-20 12:14
19-year member
UID 67277
Status Offline
Originally posted by lxmxn at 2007-6-4 16:38:

Don't blame others for not reading. Your meaning was not clear at all, so everyone was too lazy to read.

If you can't explain clearly, give an example. Don't say ambiguous words.


Hello Moderator lxmxn, it's my fault. Don't blame me, okay? Saying "sorry" here to you and also thanking you for your support

Friend terse, I used the batch processing you improved for Moderator lxmxn above
@echo off
for /f "tokens=1* delims=:" %%i in ('findstr /risc:"PCI\\\VEN_....&" *.inf') do (
echo %%j=%%~fdpi >>123.txt
)
pause

The content extracted is as follows
%DEVICE_DESCRIPTION_9K% = Install, PCI\VEN_13C1&DEV_1002&SUBSYS_100213C1=C:\M\3\1\O\oemsetup.inf
%DEVICE_DESCRIPTION_9X% = Install, PCI\VEN_13C1&DEV_1003&SUBSYS_100313C1=C:\M\3\1\O\oemsetup.inf
%aec6897.DeviceDesc% = aec689x_Inst, PCI\VEN_1191&DEV_000B&SUBSYS_1191000B=C:\M\A\6\aec6897.inf
%aec6898.DeviceDesc% = aec689x_Inst, PCI\VEN_1191&DEV_000B&SUBSYS_11916898=C:\M\A\6\aec6897.inf
%PCI\VEN_9005&DEV_00C0&SUBSYS_F6209005.DeviceDesc% = adpu160m_Inst,PCI\VEN_9005&DEV_00C0&SUBSYS_F6209005=C:\M\AD\5\ADPU160M.INF
%PCI\VEN_9005&DEV_00C0&SUBSYS_F6200E11.DeviceDesc% = adpu160m_Inst,PCI\VEN_9005&DEV_00C0&SUBSYS_F6200E11=C:\M\AD\5\ADPU160M.INF
Can you improve it again to only output the content in the red part! Really thank you

[ Last edited by baikaifang on 2007-6-4 at 10:50 PM ]
Floor 17 Posted 2007-06-04 23:04 ·  中国 湖南 永州 电信
初级用户
Credits 68
Posts 32
Joined 2006-10-20 12:14
19-year member
UID 67277
Status Offline
Originally posted by lxmxn at 2007-6-3 15:49:

The first \ unescapes the second \, resulting in a "real" \, and then this \ unescapes the special meaning of the third \. (This is how I understand it)

As for not starting with PCI\VEN, I followed the owner's description like this:


Moderator, I tried it. Two "\" and three "\" have the same output content on my side.
Floor 18 Posted 2007-06-04 23:12 ·  中国 江苏 常州 溧阳市 电信
银牌会员
★★★
Credits 2,404
Posts 946
Joined 2005-09-08 13:44
20-year member
UID 42345
Status Offline
The problem is that you don't have it in every line. Some have it, and some still don't, right? If every line were like this, then it would be okay.
Floor 19 Posted 2007-06-04 23:16 ·  中国 湖南 永州 电信
初级用户
Credits 68
Posts 32
Joined 2006-10-20 12:14
19-year member
UID 67277
Status Offline
Yeah, the extracted content is really messy. There are a lot of unnecessary things output, and there are also many duplicates. It seems really difficult to handle.
Floor 20 Posted 2007-06-05 00:22 ·  中国 江苏 常州 溧阳市 电信
银牌会员
★★★
Credits 2,404
Posts 946
Joined 2005-09-08 13:44
20-year member
UID 42345
Status Offline
Modify the moderator's version again:

@echo off&setlocal enabledelayedexpansion
for /f "delims=: tokens=1*" %%i in ('findstr /ris "PCI\\\VEN_....&" *.inf') do (
set "m=%%j"
set n=%%~fdpxi
set "m=!m:*,=!"
echo !m!=!n! >>test.txt
)
pause
Floor 21 Posted 2007-06-05 00:39 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
Try this, which requires the external command grep.

@echo off
for /r C:\M\ %%a in (*.inf) do (
for /f "tokens=1* delims=:" %%b in ('grep -o "PCI\\VEN_]\{4\}&DEV_]\{4\}&SUBSYS_]\{8\}" "%%a"') do (
echo\%%b=%%a>>result.txt
)
)


Grep download address: http://zhenlove.com.cn/cndos/fileup/files/grep.rar
Floor 22 Posted 2007-06-05 20:57 ·  中国 湖南 永州 电信
初级用户
Credits 68
Posts 32
Joined 2006-10-20 12:14
19-year member
UID 67277
Status Offline
Originally posted by terse at 2007-6-5 00:22:
Modify the moderator's version again:
@echo off&setlocal enabledelayedexpansion
for /f "delims=: tokens=1*" %%i in ('findstr /ris "PCI\\\VEN_....&" *.inf') do (
set &quo ...


It is a bit better than the previous effect, but there are still many unnecessary ones. For example:
PCI\VEN_9004&DEV_7815.DeviceDesc="Adaptec Memory Controller / XOR Engine" =C:\M\AD\8\oemsetup.inf
SupportedSubsystemIDs,%PCI\VEN_1095&DEV_3512.DeviceDesc%,0x00010001, 0x35121095=C:\M\AD\9\ASH1205.inf
%Win98SupportedControllersSubKey%,%PCI\VEN_1095&DEV_3512.DeviceDesc%,0x00010001, 0x35121095=C:\M\AD\9\ASH1205.inf
PCI\VEN_8086&DEV_24DF.DeviceDesc = "Adaptec Embedded Serial ATA HostRAID"=C:\M\AD\A\AARICH.INF

Hard work, great master.
The following version by lxmxn is basically okay. There are some duplicates. But it can be deleted manually.


Originally posted by lxmxn at 2007-6-5 00:39:
Try this, external command grep is needed.

@echo off
for /r C:\M\ %%a in (*.inf) do (
for /f "tokens=1* delims=:" %%b in ('grep -o "PCI\\VEN_]\{4\}&DEV_

Great master, the code above is very good. Thank you very much
The extracted content has the same length, and the effect is as follows:
PCI\VEN_13C1&DEV_1002&SUBSYS_100213C1=C:\M\3\1\oemsetup1.inf
PCI\VEN_13C1&DEV_1002&SUBSYS_100213C1=C:\M\3\1\O\oemsetup.inf
PCI\VEN_13C1&DEV_1003&SUBSYS_100313C1=C:\M\3\1\O\oemsetup.inf

There are also those that were not extracted with different lengths:
PCI\VEN_13C1&DEV_1000
PCI\VEN_1103&DEV_0004&REV_03

[ Last edited by baikaifang on 2007-6-5 at 09:17 PM ]
Floor 23 Posted 2007-06-05 21:14 ·  中国 湖南 永州 电信
初级用户
Credits 68
Posts 32
Joined 2006-10-20 12:14
19-year member
UID 67277
Status Offline
If the moderator modifies the code and handles the three formats respectively, then all three formats can be extracted, and finally the output files can be combined.

By the way, what is the specific meaning of the following sentence? I need to understand it so that I can modify it myself. Extract the content in different formats.

for /f "tokens=1* delims=:" %%b in ('grep -o "PCI\\VEN_[[:alnum:]]\{4\}&DEV_[[:alnum:]]\{4\}&SUBSYS_[[:alnum:]]\{8\}" "%%a"')
Floor 24 Posted 2007-06-05 21:52 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
Re baikaifang:

What characteristics of the string like "PCI\VEN_13C1&DEV_1002&SUBSYS_100213C1" that you want to extract can be "utilized"?

If there are some characteristics that distinguish it from other strings, I think things will become easier.

As for this grep command, it finds matching characters and only outputs the matching characters. If you want to study its usage in depth, you can search for relevant materials on the Internet to have a look.
Forum Jump: