标题: 如果替换掉文本中的|变成回车
[打印本页]
作者: securecrt
时间: 2009-2-4 20:52
标题: 如果替换掉文本中的|变成回车
有一段文本如下:
文件1.txt
中国|日本|美国
转换后的文件1.txt
中国
日本
美国
文件2
德国|英国
转换后的文件2.txt
德国
英国
本人新手,请高手赐教,谢谢
我关键的地方是 不知道回车在批处理里面怎么替换,可显字符还是很容易
作者: tireless
时间: 2009-2-4 21:30
标题: 搜索到的 vbs:
set fso=CreateObject("Scripting.FileSystemObject")
set file=fso.Opentextfile("文件1.txt")
set fileN=fso.Createtextfile("转换后的文件1.txt")
str=file.readall
strN=replace(str,"|",chr(10))
fileN.write strN
fileN.close
作者: securecrt
时间: 2009-2-4 21:39
非常感谢,测试通过,原先一直在想用bat批处理的变量替换...
作者: yishanju
时间: 2009-2-4 22:45
如果用FR的话 :
fr *.txt -ric:"\|" -t:"\r\n"
作者: netbenton
时间: 2009-2-4 22:49
::如果只有5个"|",可以这样,更多的话,多执行几次就可以了。
::只是会丢掉原来的空行,连续两个或多个“|”时也不会有空行。
@echo off
for /f "tokens=1-5,* delims=|" %%a in ('type 1.txt^&cd.^>1.txt^') do (
(if not '%%a==' echo.%%a
if not '%%b==' echo.%%b
if not '%%c==' echo.%%c
if not '%%d==' echo.%%d
if not '%%e==' echo.%%e
if not '%%f==' echo.%%f)>>1.txt
)