中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-03 08:55
48,038 topics / 350,123 posts / today 0 new / 48,251 members
DOS批处理 & 脚本技术(批处理室) » Question for the experts. Please help, everyone.
Printable Version  1,172 / 5
Floor1 zhaobi1234 Posted 2006-09-14 09:14
新手上路 Posts 1 Credits 11
1 .txt file contains
abc 1234 def
2.txt file contains
efg ?

How can I replace the ? in 2.txt with the 1234 from 1.txt so that 2.txt becomes
efg 1234

The 1234 here is a variable..


I hope everyone can solve this difficult problem that has bothered me for more than half a year. I'd be extremely grateful.
Floor2 9527 Posted 2006-09-14 20:42
银牌会员 Posts 438 Credits 1,185 From 北京
Actually, although the OP described the problem clearly, the conditions given are a bit too few. Just doing what you described in the post above is not hard, but it depends on what the contents of your 1.txt and 2.txt are.

@echo off&setlocal
for /f "tokens=*" %%a in (1.txt) do set aa=%%a
<nul set/p= %aa:~10,4%>>2.txt


The problem in the post above can be solved like this. I don't think the contents of your 1.txt and 2.txt are only this little, right???
Floor3 vkill Posted 2006-09-14 23:50
金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽
There are many ways to do it. You can take the 1234 in 1.txt as a parameter for call to implement it.
Floor4 namejm Posted 2006-09-15 02:46
荣誉版主 Posts 1,737 Credits 5,226 From 成都
Floor5 amao Posted 2007-02-02 20:20
中级用户 Posts 152 Credits 316
Here I will only deal with the text format you gave: 1234 is a variable, the length of the variable can change, and the number of spaces before and after the variable can also change


@echo off
sed "1s/abc*\(.*\)*def/\1/" 1.txt> temp1.txt
sed "/?/r temp1.txt" 2.txt|sed "1N;s/?.*\n\(.*\)/\1/"> temp2.txt
del temp1.txt
type temp2.txt
pause

[ Last edited by amao on 2007-2-3 at 02:33 AM ]
Floor6 gbaspps Posted 2007-02-03 08:39
新手上路 Posts 4 Credits 7
Not bad, learned something.
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023