|
voiL
中级用户
  
积分 384
发帖 189
注册 2005-10-19
状态 离线
|
『楼 主』:
如何用COPY命令合并多个文件成为一个连续的文件?
使用 LLM 解释/回答一下
操作环境:Win XP CMD(ver 5.1.2600)因工作需要,我现在需要在批处理中读取本地的一个日志文件,并把该日志改成VBS显示出来.(日志中所存内容仅为文本文件,并无VBS语句)
所以我必须在日志的前面加上(MSGbox ")及在后面加上("),然后把它改成以.vbs作后缀的脚本,并执行它.
问题是,在批处理中以如下代码操作出现了些小问题:
copy xxx.log 2.txt
echo MSGbox ">1.txt
echo ",64,"日志明细">3.txt
copy 1.txt+2.txt+3.txt 4.vbs
start 4.vbs
执行后所得到的vbs文件里在MSGbox "的后面会多出一个回车,要知道.vbs里是不允许回车的,请论坛里的各位高手指点一二.
我发现在用echo MSGbox ">1.txt时,生成的1.txt后面会多出一行空行的,我想问题就是出现在这里,能否在用echo输入里就把里面的回车删除掉???
Last edited by voiL on 2005-12-5 at 09:48 ]
Operating environment: Win XP CMD (ver 5.1.2600). Due to work needs, I now need to read a local log file in a batch file and convert the log into a VBS display. (The content stored in the log is only a text file, and there are no VBS statements.)
So I must add "(MSGbox ") at the front of the log and (") at the back, then change it to a script with the.vbs suffix and execute it.
The problem is that there are some small problems when operating with the following code in the batch file:
copy xxx.log 2.txt
echo MSGbox ">1.txt
echo ",64,"日志明细">3.txt
copy 1.txt+2.txt+3.txt 4.vbs
start 4.vbs
After execution, there will be an extra carriage return after MSGbox " in the generated vbs file. You know that carriage returns are not allowed in.vbs. Please ask the experts in the forum for guidance.
I found that when using echo MSGbox ">1.txt, an extra blank line will be added at the end of 1.txt. I think the problem is here. Can I delete the carriage return in the echo input?
Last edited by voiL on 2005-12-5 at 09:48 ]
|
|
2005-12-5 09:46 |
|
|
GOTOmsdos
铂金会员
       C++启程者
积分 5154
发帖 1827
注册 2003-7-18
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
用ECHO 就会自动增加回车换行的,要去掉他们,可以用DEBUG:
方法:
比如生成 1.txt:
echo abc>1.txt
rem 写DEBUG脚本 script:(驱除回车换行,实际就是驱除最后两个字节0D,0A)
echo n 1.txt > script
echo l >>script
echo rcx >>script
echo 3 >>script
echo w >>script
echo q >>script
rem 运行DEBUG:
debug < script
但是要算好字节.如果有多行,就比较麻烦一点.
Last edited by GOTOmsdos on 2005-12-5 at 13:37 ]
Using ECHO will automatically add carriage returns and line feeds. To remove them, you can use DEBUG:
Method:
For example, generate 1.txt:
echo abc>1.txt
rem Write the DEBUG script script: (remove carriage returns and line feeds, actually just remove the last two bytes 0D, 0A)
echo n 1.txt > script
echo l >>script
echo rcx >>script
echo 3 >>script
echo w >>script
echo q >>script
rem Run DEBUG:
debug < script
But you need to calculate the bytes well. If there are multiple lines, it will be more troublesome.
Last edited by GOTOmsdos on 2005-12-5 at 13:37 ]
|
|
2005-12-5 13:29 |
|
|
voiL
中级用户
  
积分 384
发帖 189
注册 2005-10-19
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
谢谢GOTOmsdos兄,您的方法我试过了,在超过3字节情况下只它会删后面的.
如果要修改起来不是很好控制.
因为我的日志文件也是用echo写进去的,所以大小会不断地增加.
Last edited by voiL on 2005-12-5 at 17:41 ]
Thanks to brother GOTOmsdos, I have tried your method. When it exceeds 3 bytes, it will only delete the following ones.
It is not very easy to control when modifying.
Because my log file is also written in with echo, so the size will keep increasing.
Last edited by voiL on 2005-12-5 at 17:41 ]
|
|
2005-12-5 16:04 |
|
|
GOTOmsdos
铂金会员
       C++启程者
积分 5154
发帖 1827
注册 2003-7-18
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
看来还是要编程序解决的..
编个简单的C控制台程序就可以拉.. 然后批处理,放到计划任务里..
It seems that it still needs to be solved by writing a program.. Just write a simple C console program.. Then a batch script, put it in the task scheduler..
|
|
2005-12-5 18:57 |
|
|
willsort
元老会员
         Batchinger
积分 4432
发帖 1512
注册 2002-10-18
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
Re voiL:
可以考虑使用 Debug 中的内嵌汇编,将 cx 值减 2 ,如果 log 文件超过 64K,则需要兼顾 bx 与 cx 值。当然,这样的方法仍然是比较笨拙的。可以考率使用字符串替换工具根据将 log 文件中 0d 0a 替换为空,或者使用其它可以处理带回车文本的 vbs 函数。
Re voiL:
Consider using the inline assembly in Debug to subtract 2 from the cx value. If the log file exceeds 64K, you need to take both bx and cx values into account. Of course, this method is still relatively clumsy. You can consider using a string replacement tool to replace 0d 0a in the log file with empty, or use other VBS functions that can handle text with carriage returns.
|

※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得! |
|
2005-12-5 19:06 |
|
|
无奈何
荣誉版主
      
积分 1338
发帖 356
注册 2005-7-15
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
你如果可以用第三方工具的话,很简单。
下面是用 SED 的解决方案:
sed -e "1s/^/MSGbox\"/" -e "$s/$/\",64,\"日志明细\"/" xxx.log>4.vbs
If you can use a third - party tool, it's very simple.
The following is the solution using SED:
sed -e "1s/^/MSGbox\"/" -e "$s/$/\",64,\"Log Details\"/" xxx.log>4.vbs
|

☆开始\运行 (WIN+R)☆
%ComSpec% /cset,=何奈无── 。何奈可无是原,事奈无做人奈无&for,/l,%i,in,(22,-1,0)do,@call,set/p= %,:~%i,1%<nul&ping/n 1 127.1>nul
|
|
2005-12-6 12:06 |
|
|