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-01 15:47
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Problems with batch string operations and replacements View 1,647 Replies 4
Original Poster Posted 2006-04-06 06:45 ·  中国 福建 厦门 电信
系统支持
★★★
Credits 904
Posts 339
Joined 2002-10-10 00:00
23-year member
UID 1904
From 厦门
Status Offline
Recently encountered a problem. The version above V6.0 of "All-in-one String Batch Replace" couldn't achieve it, so I thought about using batch processing. But it didn't work out... I post it to ask the moderators and those who know, thanks in advance.

Replace all , , , .... in the following text with , , , ,....., that is, the numbers in the square brackets are uniformly added by a certain number.

	

ImgFileName="pic2/806.jpg";
Scale=100;
PhotoWidth=450;
PhotoHeight=620;;
TransEffects="";

ImgFileName="pic2/807.jpg";
Scale=100;
PhotoWidth=450;
PhotoHeight=620;;
TransEffects="";

ImgFileName="pic2/808.jpg";
Scale=100;
PhotoWidth=450;
PhotoHeight=620;;
TransEffects="";

ImgFileName="pic2/809.jpg";
Scale=100;
PhotoWidth=580;
PhotoHeight=445;
TransEffects="";

...........................


Processed with batch processing into:


	

ImgFileName="pic2/806.jpg";
Scale=100;
PhotoWidth=450;
PhotoHeight=620;;
TransEffects="";

ImgFileName="pic2/807.jpg";
Scale=100;
PhotoWidth=450;
PhotoHeight=620;;
TransEffects="";

ImgFileName="pic2/808.jpg";
Scale=100;
PhotoWidth=450;
PhotoHeight=620;;
TransEffects="";

ImgFileName="pic2/809.jpg";
Scale=100;
PhotoWidth=580;
PhotoHeight=445;
TransEffects="";

...........................


Everyone give a method or discuss it.
Floor 2 Posted 2006-04-06 10:33 ·  中国 重庆 巴南区 电信
高级用户
★★
Credits 772
Posts 273
Joined 2004-10-23 00:00
21-year member
UID 32861
Gender Male
Status Offline
Just use change.
http://www.msfans.net/bbs/
Floor 3 Posted 2006-04-06 18:39 ·  中国 福建 泉州 电信
银牌会员
★★★
Credits 1,276
Posts 469
Joined 2002-12-23 13:00
23-year member
UID 586
Gender Male
From 福建泉州
Status Offline
Replace a.txt with the original file and replace B.txt with the finally generated file. I wonder if it can meet your requirements. This cannot handle blank lines, that is, all blank lines will be deleted after running.

@echo off
setlocal EnableDelayedExpansion
for /f "usebackq tokens=1,2,3* delims=" %%i in (a.txt) do (
if not "%%j"=="" (
set a=%%j
set /a a=!a!+49
echo %%i%%k>>b.txt
) else echo. %%i%%j%%k>>b.txt
)

QQ:366840202
http://chenall.net
Floor 4 Posted 2006-04-06 21:44 ·  中国 辽宁 锦州 中移铁通
荣誉版主
★★★
Credits 1,338
Posts 356
Joined 2005-07-15 12:09
21-year member
UID 40733
Gender Male
Status Offline
If you are willing to try, use AWK to have a go.
AWK download address: http://www.cs.bell-labs.com/cm/cs/who/bwk/awk95.exe

awk -F"\n" "{sub(/\+\]/,\"\")-index($0,\"\");print}" test.txt
  ☆开始\运行 (WIN+R)☆
%ComSpec% /cset,=何奈无── 。何奈可无是原,事奈无做人奈无&for,/l,%i,in,(22,-1,0)do,@call,set/p= %,:~%i,1%<nul&ping/n 1 127.1>nul

Floor 5 Posted 2006-04-07 00:29 ·  中国 福建 厦门 电信
系统支持
★★★
Credits 904
Posts 339
Joined 2002-10-10 00:00
23-year member
UID 1904
From 厦门
Status Offline
Thanks to the help of the above几位 brothers, the method I finally used is the AWK method provided by "Wu Nai He".

Just added " >test1.txt" later to output again.

Although this change was not used this time, I am still very grateful. Thank you.
Forum Jump: