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-08-06 07:26
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] A very urgent text deletion problem, I'm about to cry >< View 709 Replies 8
Original Poster Posted 2007-10-31 02:01 ·  中国 台湾 中华电信(HiNet)数据中心
初级用户
Credits 96
Posts 43
Joined 2007-10-31 01:20
18-year member
UID 101245
Gender Male
Status Offline
Hello everyone, I help manage a forum I set up for a friend.
This forum uses a CGI program, so the forum's data is all in text files.
But some problems came up while editing the text files, please help me ><


The text files use as the separator.

I want to find in all text files and delete everything between the last, second-to-last, and third-to-last ∥ separators.
Example as follows:

Before processing:


1∥PowerDirector 6 practical online tutorial∥Who am I∥123@yahoo.com.tw∥This webpage cannot be linked<br>∥2007/10/11 10:55∥219.84.136.241d6wRPnMHgj46Q1192071350QBIFBW3Q

After processing:

1∥PowerDirector 6 practical online tutorial∥Who am I∥123@yahoo.com.tw∥This webpage cannot be linked<br>∥2007/10/11 10:55∥219.84.136.241∥

Simply put, as long as everything after 219.84.136.241 can be deleted, that's fine.
But 219.84.136.241 is the user's IP, so it is an irregular string.


Please help, thank you very, very, very much, it's urgent ><
Many thanks

[ Last edited by leo1984 on 2007-10-31 at 02:03 AM ]
Floor 2 Posted 2007-10-31 02:32 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
leo1984 +1 2007-10-31 03:04
Floor 3 Posted 2007-10-31 02:48 ·  中国 台湾 中华电信(HiNet)数据中心
初级用户
Credits 96
Posts 43
Joined 2007-10-31 01:20
18-year member
UID 101245
Gender Male
Status Offline
Thank you very much for your kind help.
But if I change Oldlist.txt to *.txt, that means opening all text files.
Then how can I save the modified text files directly themselves, without outputting Newlist.txt
instead?

[ Last edited by leo1984 on 2007-10-31 at 02:49 AM ]
Floor 4 Posted 2007-10-31 09:06 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
In batch files you can't directly read from and save to the same text file at the same time, otherwise the new data will directly overwrite the old data.

Test it yourself first.
@echo off
md Temp
for /f "delims=" %%f in ('dir /on/b "*.txt"') do (
echo.>Temp\%%~nfNew.txt
for /f "tokens=1,2,3,4,5,6,7 delims=∥" %%i in (%%f) do echo %%i∥%%j∥%%k∥%%l∥%%m∥%%n∥%%o∥>>Temp\%%~nfNew.txt
)
pause


[ Last edited by zh159 on 2007-10-31 at 09:08 AM ]
Floor 5 Posted 2007-10-31 09:23 ·  中国 浙江 衢州 中移铁通
银牌会员
★★★
Credits 1,436
Posts 739
Joined 2007-10-11 17:44
18-year member
UID 99469
Gender Male
Status Offline
Floor 6 Posted 2007-10-31 09:42 ·  中国 台湾 中华电信(HiNet)数据中心
初级用户
Credits 96
Posts 43
Joined 2007-10-31 01:20
18-year member
UID 101245
Gender Male
Status Offline
Thank you very much for your help, zh159, it has already been solved successfully.
I also wish you all the best ^^

Also thanks to abcd, but I tested that section too, and it seems it only searched for the string and didn't really do anything. Thanks to you as well ^^
Floor 7 Posted 2007-10-31 11:10 ·  中国 广东 广州 电信
初级用户
Credits 90
Posts 40
Joined 2007-04-08 04:50
19-year member
UID 84350
Gender Male
From 广州
Status Offline
Why is the OP's text in Traditional Chinese? It feels so awkward to read!
Floor 8 Posted 2007-10-31 12:53 ·  中国 台湾 中华电信(HiNet)数据中心
初级用户
Credits 96
Posts 43
Joined 2007-10-31 01:20
18-year member
UID 101245
Gender Male
Status Offline
Sorry,
because I'm a user from Taiwan, I can only type in Traditional Chinese ^^"
Floor 9 Posted 2007-10-31 15:52 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
Not just Taiwan, Hong Kong uses Traditional Chinese too (I'm from the mainland ^_^)

Simplified Chinese is convenient for writing, but Traditional Chinese may show more skill in calligraphy; Simplified should be promoted, but Traditional must not be forgotten ^_^
Forum Jump: