|
zqz0012005
中级用户
  
积分 297
发帖 135
注册 2006-10-21
状态 离线
|
『第 16 楼』:
使用 LLM 解释/回答一下
Originally posted by 26933062 at 2008-5-29 09:35 PM:
呵呵,楼上的就真的存在效率问题了。
我也考虑过效率问题
只是想过另外一个问题:系统处理!str:~0,1!进行变量截取时不需要花时间吗?
结合大家的讨论,变量截取的效率可能比findstr高吧
我觉得WANKOILZ兄的还应该完善一下
if "!str:~0,1!"=="" echo.
Last edited by zqz0012005 on 2008-5-29 at 09:56 PM ]
Originally posted by 26933062 at 2008-5-29 09:35 PM:
Hehe, the person above really has an efficiency issue.
I also considered the efficiency issue.
Just thought of another question: Doesn't the system spend time when processing!str:~0,1! for variable truncation?
Combined with everyone's discussion, variable truncation may be more efficient than findstr.
I think Brother WANKOILZ's should still be improved.
if "!str:~0,1!"=="" echo.
Last edited by zqz0012005 on 2008-5-29 at 09:56 PM ]
此帖被 +1 点积分 点击查看详情 评分人:【 amio 】 | 分数: +1 | 时间:2008-5-29 22:21 |
|
|

hh.exe ntcmds.chm::/ntcmds.htm
 |
|
2008-5-29 21:54 |
|
|
WANKOILZ
初级用户
 
积分 198
发帖 89
注册 2007-9-6 来自 重庆
状态 离线
|
『第 17 楼』:
使用 LLM 解释/回答一下
呵呵,我只是想针对楼主那种简单形式的文本,就没用完善的方法,管道+findstr会降低效率。当然要考虑周全也只有用findstr了。
Hehe, I just want to target the simple form of text by the original poster, and the method is not perfect. Piping + findstr will reduce efficiency. Of course, if you want to be comprehensive, you can only use findstr.
|
|
2008-5-29 21:58 |
|
|
amio
中级用户
  
积分 206
发帖 93
注册 2007-8-16
状态 离线
|
『第 18 楼』:
使用 LLM 解释/回答一下
我那不是简单的文本 就是改inf 文件
先帮我看看 15楼的问题吧
What I have isn't simple text; it's just modifying INF files. First, help me take a look at the problem on floor 15.
|
|
2008-5-29 22:02 |
|
|
26933062
银牌会员
    
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『第 19 楼』:
使用 LLM 解释/回答一下
判断有
@echo off&setlocal enabledelayedexpansion
for /f "tokens=*" %%a in (a.txt) do (
set "str=%%a"
set "str=!str:
Determine if there is a
@echo off&setlocal enabledelayedexpansion
for /f "tokens=*" %%a in (a.txt) do (
set "str=%%a"
set "str=!str:
此帖被 +2 点积分 点击查看详情 评分人:【 amio 】 | 分数: +2 | 时间:2008-5-29 22:20 |
|
|

致精致简! |
|
2008-5-29 22:07 |
|
|
WANKOILZ
初级用户
 
积分 198
发帖 89
注册 2007-9-6 来自 重庆
状态 离线
|
『第 20 楼』:
使用 LLM 解释/回答一下
同时去掉行前面的空格: @echo off&setlocal enabledelayedexpansion
for /f "delims=" %%i in (1.txt) do (
echo %%i|findstr "^\$">nul&&echo.
for %%j in (%%i) do set str=!str! %%j
echo !str:~1!&set str=
)
pause>nul
符号在findstr里用作普通符号的话要用 \ 转义才行,26和zq兄忽视了,我也是测试前面的代码后发现的。
Last edited by WANKOILZ on 2008-5-29 at 10:27 PM ]
Remove the spaces in front of the lines at the same time:
@echo off&setlocal enabledelayedexpansion
for /f "delims=" %%i in (1.txt) do (
echo %%i|findstr "^\$">nul&&echo.
for %%j in (%%i) do set str=!str! %%j
echo !str:~1!&set str=
)
pause>nul
The symbols need to be escaped with \ if used as ordinary symbols in findstr. Brothers 26 and zq ignored this, and I also discovered it after testing the previous code.
Last edited by WANKOILZ on 2008-5-29 at 10:27 PM ]
|
|
2008-5-29 22:16 |
|
|
26933062
银牌会员
    
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『第 21 楼』:
使用 LLM 解释/回答一下
19 楼代码可以去掉行前面的空格啊。。。。。
echo %%i|findstr "^\[.*\]$">nul 此种方法效率很低啊。
The code on floor 19 can remove the spaces in front of the lines...
echo %%i|findstr "^\$">nul This method is very inefficient.
|

致精致简! |
|
2008-5-29 22:23 |
|
|
amio
中级用户
  
积分 206
发帖 93
注册 2007-8-16
状态 离线
|
『第 22 楼』:
使用 LLM 解释/回答一下
Originally posted by WANKOILZ at 2008-5-29 10:16 PM:
同时去掉行前面的空格:@echo off&setlocal enabledelayedexpansion
for /f "delims=" %%i in (1.txt) do (
echo %%i|findstr "^\$">nul&&echo.
fo ...
这个 测试 。。。
cc dd 会把cc 一起给删掉
Originally posted by WANKOILZ at 2008-5-29 10:16 PM:
Remove the spaces in front of the lines at the same time:
@echo off&setlocal enabledelayedexpansion
for /f "delims=" %%i in (1.txt) do (
echo %%i|findstr "^\$">nul&&echo.
fo ...
This is a test...
cc dd will delete cc together
|
|
2008-5-29 22:25 |
|
|
WANKOILZ
初级用户
 
积分 198
发帖 89
注册 2007-9-6 来自 重庆
状态 离线
|
『第 23 楼』:
使用 LLM 解释/回答一下
回楼上:已经改进,但是不如26933062的好用,tokens=*是保证去掉行前的空格,并且后面的数据不变,应该是最好的方法了。
至于findstr "^\[.*\]$">nul 这种格式我也是第一次用,但是"^[.*]$"这种格式不行呢。
Reply to the upstairs: It has been improved, but it's not as easy to use as 26933062's. tokens=* ensures that the spaces before the line are removed and the subsequent data remains unchanged, which should be the best method. As for the format like findstr "^\$">nul, I'm using it for the first time, but the format like "^$" doesn't work.
|
|
2008-5-29 22:29 |
|
|
zqz0012005
中级用户
  
积分 297
发帖 135
注册 2006-10-21
状态 离线
|
『第 24 楼』:
使用 LLM 解释/回答一下
忘记了“”在findstr中是特殊字符
tokens=*去掉行首空格,小楼总能别出心裁,果然经济实惠!
Last edited by zqz0012005 on 2008-5-29 at 10:32 PM ]
Forgot that "" are special characters in findstr
tokens=* removes leading spaces, Xiao Lou can always be innovative, really cost-effective!
Last edited by zqz0012005 on 2008-5-29 at 10:32 PM ]
|

hh.exe ntcmds.chm::/ntcmds.htm
 |
|
2008-5-29 22:30 |
|
|
26933062
银牌会员
    
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『第 25 楼』:
使用 LLM 解释/回答一下
完全匹配 的方法
@echo off
for /f "delims=:" %%a in ('findstr /n ".*\" a.txt') do set .%%a=a
for /f "tokens=1* delims=:" %%a in ('findstr /n .* a.txt') do (
if defined .%%a echo.
for /f "tokens=*" %%i in ("%%b") do echo.%%i
)
pause
Methods to completely match
@echo off
for /f "delims=:" %%a in ('findstr /n ".*\" a.txt') do set .%%a=a
for /f "tokens=1* delims=:" %%a in ('findstr /n .* a.txt') do (
if defined .%%a echo.
for /f "tokens=*" %%i in ("%%b") do echo.%%i
)
pause
|

致精致简! |
|
2008-5-29 22:35 |
|
|
WANKOILZ
初级用户
 
积分 198
发帖 89
注册 2007-9-6 来自 重庆
状态 离线
|
『第 26 楼』:
使用 LLM 解释/回答一下
楼上方法真独特。
但是我对 .*\[..*\] 不解:
1、为什么后面不加 .* 如:.*\[..*\].*
2、..* 这里的两点是什么意思呢。
劳驾楼上讲解下。
The method upstairs is really unique.
But I don't understand ".*\":
1. Why isn't ".*" added later, such as: .*\.*
2. What does the two dots mean in "..*".
Please explain it for me upstairs.
|
|
2008-5-29 22:45 |
|
|
amio
中级用户
  
积分 206
发帖 93
注册 2007-8-16
状态 离线
|
『第 27 楼』:
使用 LLM 解释/回答一下
还有个问题。。。
能不能删除 ; 打头的行 就是注释 而不删除字符中间夹着的 ;
; asdasdasd
asd;asd
; qweqewqwe
---------------------------
asd;asd
There is also a problem...
Can we delete the lines starting with ; which are comments without deleting the ; in the middle of characters?
; asdasdasd
asd;asd
; qweqewqwe
---------------------------
asd;asd
|
|
2008-5-29 22:51 |
|
|
26933062
银牌会员
    
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『第 28 楼』:
使用 LLM 解释/回答一下
*代表重复前面字符的0或n次
.代表至少一个字符。
如果是".*\[.*\]" 这样的话,那么也匹配 [] 这样的结果了。即:[]中间没有内容也匹配了。
* represents 0 or n repetitions of the preceding character.
. represents at least one character.
If it is ".\*\", then it also matches the result of like this. That is: the content between is not matched.
|

致精致简! |
|
2008-5-29 22:52 |
|
|
WANKOILZ
初级用户
 
积分 198
发帖 89
注册 2007-9-6 来自 重庆
状态 离线
|
『第 29 楼』:
使用 LLM 解释/回答一下
*代表重复前面字符的0或n次
.代表至少一个字符。
如果是".*\" 这样的话,那么也匹配 这样的结果了。即:中间没有内容也匹配了。 说的很清楚,感谢了。
还有,再劳驾:为什么不在后面再加个 .* 形如:".*\.*" ,这样和不加有什么区别?
回27楼:25楼的代码符合你的要求
Last edited by WANKOILZ on 2008-5-29 at 10:59 PM ]
* means 0 or n repetitions of the preceding character
. means at least one character.
If it is ".*\", then it will also match results like . That is: with no content inside also matches. It is very clear, thank you.
Also, please help again: Why not add .* at the end, in the form of ".*\.*", what is the difference between this and not adding it?
Reply to post 27: The code in post 25 meets your requirements
Last edited by WANKOILZ on 2008-5-29 at 10:59 PM ]
|
|
2008-5-29 22:57 |
|
|
zqz0012005
中级用户
  
积分 297
发帖 135
注册 2006-10-21
状态 离线
|
『第 30 楼』:
使用 LLM 解释/回答一下
如果后面再加个 .*,则像[reg]add这样不是以]结尾的行也会匹配,而这样的行不是楼主想的要吧
If you add .* later, then lines like add which do not end with ] will also be matched, and such lines are not what the original poster wants.
|

hh.exe ntcmds.chm::/ntcmds.htm
 |
|
2008-5-29 23:01 |
|