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-20 02:06
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » New space deletion problem?? View 2,467 Replies 40
Floor 16 Posted 2008-05-29 21:54 ·  中国 四川 成都 电信
中级用户
★★
Credits 297
Posts 135
Joined 2006-10-21 12:00
19-year member
UID 67627
Gender Male
Status Offline
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 ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
amio +1 2008-05-29 22:21
Floor 17 Posted 2008-05-29 21:58 ·  中国 重庆 电信
初级用户
★★
Credits 198
Posts 89
Joined 2007-09-06 23:22
18-year member
UID 96746
Gender Male
From 重庆
Status Offline
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.
Floor 18 Posted 2008-05-29 22:02 ·  中国 北京 联通互联网数据中心
中级用户
★★
Credits 206
Posts 93
Joined 2007-08-16 17:19
18-year member
UID 95263
Gender Male
Status Offline
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.
Floor 19 Posted 2008-05-29 22:07 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
Determine if there is a

@echo off&setlocal enabledelayedexpansion
for /f "tokens=*" %%a in (a.txt) do (
set "str=%%a"
set "str=!str:




Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
amio +2 2008-05-29 22:20
致精致简!
Floor 20 Posted 2008-05-29 22:16 ·  中国 重庆 电信
初级用户
★★
Credits 198
Posts 89
Joined 2007-09-06 23:22
18-year member
UID 96746
Gender Male
From 重庆
Status Offline
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 ]
Floor 21 Posted 2008-05-29 22:23 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
The code on floor 19 can remove the spaces in front of the lines...
echo %%i|findstr "^\[.*\]$">nul This method is very inefficient.
致精致简!
Floor 22 Posted 2008-05-29 22:25 ·  中国 上海 电信
中级用户
★★
Credits 206
Posts 93
Joined 2007-08-16 17:19
18-year member
UID 95263
Gender Male
Status Offline
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
Floor 23 Posted 2008-05-29 22:29 ·  中国 重庆 电信
初级用户
★★
Credits 198
Posts 89
Joined 2007-09-06 23:22
18-year member
UID 96746
Gender Male
From 重庆
Status Offline
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.
Floor 24 Posted 2008-05-29 22:30 ·  中国 四川 成都 电信
中级用户
★★
Credits 297
Posts 135
Joined 2006-10-21 12:00
19-year member
UID 67627
Gender Male
Status Offline
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 ]
Floor 25 Posted 2008-05-29 22:35 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
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
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
WANKOILZ +2 2008-05-29 22:41
致精致简!
Floor 26 Posted 2008-05-29 22:45 ·  中国 重庆 电信
初级用户
★★
Credits 198
Posts 89
Joined 2007-09-06 23:22
18-year member
UID 96746
Gender Male
From 重庆
Status Offline
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.
Floor 27 Posted 2008-05-29 22:51 ·  中国 上海 电信
中级用户
★★
Credits 206
Posts 93
Joined 2007-08-16 17:19
18-year member
UID 95263
Gender Male
Status Offline
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
Floor 28 Posted 2008-05-29 22:52 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
* 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.
致精致简!
Floor 29 Posted 2008-05-29 22:57 ·  中国 重庆 电信
初级用户
★★
Credits 198
Posts 89
Joined 2007-09-06 23:22
18-year member
UID 96746
Gender Male
From 重庆
Status Offline
* 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 ]
Floor 30 Posted 2008-05-29 23:01 ·  中国 四川 成都 电信
中级用户
★★
Credits 297
Posts 135
Joined 2006-10-21 12:00
19-year member
UID 67627
Gender Male
Status Offline
If you add .* later, then lines like [reg]add which do not end with ] will also be matched, and such lines are not what the original poster wants.
Forum Jump: