标题: 【求助】怎么向文本文件加入空行
[打印本页]
作者: terrytong
时间: 2008-8-6 17:47
标题: 【求助】怎么向文本文件加入空行
我有个文本文件,现在需要向里面的所有的单行后加一空行。
一定要是空行,不能有空格。
我用 echo.>>xx.txt为什么不行啊。
只有第一次没有.号,其他的都有个。号。
知道的人帮帮我啊。
作者: HAT
时间: 2008-8-6 20:06
把你的完整代码贴出来看看
作者: terrytong
时间: 2008-8-6 21:14
Quote: |
Originally posted by HAT at 2008-8-6 20:06:
把你的完整代码贴出来看看 |
|
@echo off
title set station ID for mPCIe
mode con cols=100 lines=20
setlocal enabledelayedexpansion
set /p IP=please input the IP number:
set /p ID=please input the ID number:
cd\
d:
for /r d:\zt4_rev\T1 %%a in (*.cfg) do (
set temp=%%a
set mo=!temp:~16,14!
set phase=!temp:~13,2!
set dirc=!temp:~0,31!
cd !dirc!
del sfis.cfg
echo [PN]>>sfis.cfg
echo MP_PN=!mo!>>sfis.cfg
echo RMA_PN=NA>>sfis.cfg
echo SN_LENGTH=13>>sfis.cfg
echo.>>sfis.cfg
echo [SFIS]>>sfis.cfg
echo Enable=1>>sfis.cfg
echo SFIS_TIMEOUT = 25000>>sfis.cfg
echo SFIS_IP=10.5.5.!IP!>>sfis.cfg
echo SFIS_Port=5010>>sfis.cfg
echo FixtureID=!phase!_!ID!>>sfis.cfg
echo LINE=ZT4>>sfis.cfg
echo.>>sfis.cfg
echo [Station]>>sfis.cfg
echo ChipId=none>>sfis.cfg
echo FA_Debug=disable>>sfis.cfg
echo SfCheckAutoFocus=disable>>sfis.cfg
echo.>>sfis.cfg
echo [GrayBox]>>sfis.cfg
echo R=255>>sfis.cfg
echo G=0>>sfis.cfg
echo B=0>>sfis.cfg
echo Message="ERROR!">>sfis.cfg
echo.>>sfis.cfg
echo [ImageFile]>>sfis.cfg
echo Enable=0>>sfis.cfg
echo ApplicationPath=fciv.exe>>sfis.cfg
echo CheckSumPath=imagefile_12MB.cks>>sfis.cfg
echo ConfigPath=param.ini>>sfis.cfg
echo BlockName=Options>>sfis.cfg
echo ItemName=UpLoadImagePath>>sfis.cfg
)
只有第一个目录得到想要的结果,其他的都如下:
[PN]
MP_PN=1602-276201-02
RMA_PN=NA
SN_LENGTH=13
.
[SFIS]
Enable=
SFIS_TIMEOUT = 25000
SFIS_IP=10.5.5.80
SFIS_Port=5010
FixtureID=T1_27
LINE=ZT4
.
[Station]
ChipId=none
FA_Debug=disable
SfCheckAutoFocus=disable
.
[GrayBox]
R=255
Message="ERROR"
.
[ImageFile]
Enable=
ApplicationPath=fciv.exe
CheckSumPath=imagefile_12MB.cks
ConfigPath=param.ini
BlockName=Options
ItemName=UpLoadImagePath
作者: lxmxn
时间: 2008-8-6 21:30
echo. 应该只会输出一个空行,不会输入多余的点,仔细检查一下你的代码,看是不是写成了“echo[空格].”……
作者: flyinspace
时间: 2008-8-6 21:34
他的代码没问题啊?
还有尽量少用 for 里面的 !扩展.情愿用call语句 调用.
想理解的话。写一个多for的循环语句就可以明白 了。
作者: terrytong
时间: 2008-8-6 21:41
echo.中绝对没有空格,为什么只有第一个目录里没有多余的点?
还有就是
echo G=0>>sfis.cfg
echo B=0>>sfis.cfg
输出时0不见了。
但是如果set zero=0
用!zero!就没有问题。
作者: obsolete
时间: 2008-8-6 22:06
echo G=^0>>sfis.cfg
好像不转义的话,这里0当作句柄用了
作者: obsolete
时间: 2008-8-6 22:09
echo Message="ERROR^!">>sfis.cfg
貌似!也要转义
作者: obsolete
时间: 2008-8-6 22:47
貌似找不到问题所在,把问题简化一下贴上来
for /r d:\zt4_rev\T1 %%a in (*.t) do echo.hello
pause
[
Last edited by obsolete on 2008-8-6 at 11:05 PM ]
作者: obsolete
时间: 2008-8-6 23:22
如5楼所说,可以用call,echo.
for /r d:\zt4_rev\T1 %%a in (*.t) do call,echo.hello
pause
[
Last edited by obsolete on 2008-8-6 at 11:26 PM ]
作者: HAT
时间: 2008-8-7 01:08
@echo off
title set station ID for mPCIe
mode con cols=100 lines=20
setlocal enabledelayedexpansion
set /p IP=please input the IP number:
set /p ID=please input the ID number:
cd\
d:
for /r d:\zt4_rev\T1 %%a in (*.cfg) do (
set temp=%%a
set mo=!temp:~16,14!
set phase=!temp:~13,2!
set dirc=!temp:~0,31!
cd !dirc!
del sfis.cfg
>>sfis.cfg echo [PN]
>>sfis.cfg echo MP_PN=!mo!
>>sfis.cfg echo RMA_PN=NA
>>sfis.cfg echo SN_LENGTH=13
>>sfis.cfg echo.
>>sfis.cfg echo [SFIS]
>>sfis.cfg echo Enable=1
>>sfis.cfg echo SFIS_TIMEOUT = 25000
>>sfis.cfg echo SFIS_IP=10.5.5.!IP!
>>sfis.cfg echo SFIS_Port=5010
>>sfis.cfg echo FixtureID=!phase!_!ID!
>>sfis.cfg echo LINE=ZT4
>>sfis.cfg echo.
>>sfis.cfg echo [Station]
>>sfis.cfg echo ChipId=none
>>sfis.cfg echo FA_Debug=disable
>>sfis.cfg echo SfCheckAutoFocus=disable
>>sfis.cfg echo.
>>sfis.cfg echo [GrayBox]
>>sfis.cfg echo R=255
>>sfis.cfg echo G=0
>>sfis.cfg echo B=0
>>sfis.cfg echo Message="ERROR!"
>>sfis.cfg echo.
>>sfis.cfg echo [ImageFile]
>>sfis.cfg echo Enable=0
>>sfis.cfg echo ApplicationPath=fciv.exe
>>sfis.cfg echo CheckSumPath=imagefile_12MB.cks
>>sfis.cfg echo ConfigPath=param.ini
>>sfis.cfg echo BlockName=Options
>>sfis.cfg echo ItemName=UpLoadImagePath
)
作者: terrytong
时间: 2008-8-7 16:33
Quote: |
Originally posted by HAT at 2008-8-7 01:08:
[code]@echo off
title set station ID for mPCIe
mode con cols=100 lines=20
setlocal enabledelayedexpansion
set /p IP=please input the IP number:
set /p ID=please input the ID number:
cd\
d: ... |
|
echo G=^0>>sfis.cfg的问题解决了,但是还是多了个。号。
作者: HAT
时间: 2008-8-7 23:00
哪里多了句号?鸟巢还是水立方?
作者: flyinspace
时间: 2008-8-8 01:57
哎.知道么?
批处理中。尽量不要用
cd,这样的指令呢.
要不迟早你会后悔的.
作者: HAT
时间: 2008-8-8 11:54
用cd不要紧,在后面判断一下就行了。
否则,如楼上所说,早晚要后悔。
作者: terrytong
时间: 2008-8-8 17:09
Quote: |
Originally posted by HAT at 2008-8-8 11:54:
用cd不要紧,在后面判断一下就行了。
否则,如楼上所说,早晚要后悔。 |
|
我判断过了,cd !dirc! 没有问题。
但是结果为:
[PN]
MP_PN=1602-276201-02
RMA_PN=NA
SN_LENGTH=13
.
[SFIS]
Enable=0
SFIS_TIMEOUT = 25000
SFIS_IP=10.5.5.80
SFIS_Port=5010
FixtureID=T1_27
LINE=ZT4
.
[Station]
ChipId=none
FA_Debug=disable
SfCheckAutoFocus=disable
.
[GrayBox]
R=255
G=0
B=0
Message="ERROR"
.
[ImageFile]
Enable=0
ApplicationPath=fciv.exe
CheckSumPath=imagefile_12MB.cks
ConfigPath=param.ini
BlockName=Options
ItemName=UpLoadImagePath
作者: terrytong
时间: 2008-8-8 17:59
@echo off
title set station ID for mPCIe
mode con cols=100 lines=20
setlocal enabledelayedexpansion
set /p IP=please input the IP number:
set /p ID=please input the ID number:
set one=1
set zero=0
cd\
d:
for /r d:\zt4_mpcie %%a in (*.cfg) do (
set temp=%%a
set mo=!temp:~16,14!
set phase=!temp:~13,2!
set dirc=!temp:~0,31!
cd !dirc!
del sfis.cfg
echo [PN]>>sfis.cfg
echo MP_PN=!mo!>>sfis.cfg
echo RMA_PN=NA>>sfis.cfg
echo SN_LENGTH=13>>sfis.cfg
echo^.>>sfis.cfg
echo [SFIS]>>sfis.cfg
echo Enable=!one!>>sfis.cfg
echo SFIS_TIMEOUT = 25000>>sfis.cfg
echo SFIS_IP=10.5.5.!IP!>>sfis.cfg
echo SFIS_Port=5010>>sfis.cfg
echo FixtureID=!phase!_!ID!>>sfis.cfg
echo LINE=ZT4>>sfis.cfg
echo^.>>sfis.cfg
echo [Station]>>sfis.cfg
if !mo!=T1 call :upload
if !mo!=T2 call :check
if !mo!=T3 call :check
echo FA_Debug=disable>>sfis.cfg
echo SfCheckAutoFocus=disable>>sfis.cfg
echo^.>>sfis.cfg
echo [GrayBox]>>sfis.cfg
echo R=255>>sfis.cfg
echo G=!zero!>>sfis.cfg
echo B=!zero!>>sfis.cfg
echo Message="ERROR!">>sfis.cfg
echo^.>>sfis.cfg
echo [ImageFile]>>sfis.cfg
echo Enable=!zero!>>sfis.cfg
echo ApplicationPath=fciv.exe>>sfis.cfg
echo CheckSumPath=imagefile_12MB.cks>>sfis.cfg
echo ConfigPath=param.ini>>sfis.cfg
echo BlockName=Options>>sfis.cfg
echo ItemName=UpLoadImagePath>>sfis.cfg
)
goto end
:upload
echo ChipId=upload>>sfis.cfg
goto eof
:check
echo ChipId=check>>sfis.cfg
goto eof
:end
end
为什么我加了IF后就会出错?
if !mo!=T1 call :upload
if !mo!=T2 call :check
if !mo!=T3 call :check
作者: flyinspace
时间: 2008-8-8 18:47
=是赋值
==是比较。
所以很自然报错咯。
作者: terrytong
时间: 2008-8-10 09:40
我把那个要处理的文件上传了,哪位高手可以帮忙看看啊,到里是哪里出错了?我写的是:
@echo off
title set station ID for mPCIe
mode con cols=100 lines=20
setlocal enabledelayedexpansion
set /p IP=please input the IP number:
set /p ID=please input the ID number:
set one=1
set zero=0
cd\
d:
for /r d:\zt4_rev %%a in (*.cfg) do (
set temp=%%a
set mo=!temp:~14,14!
set phase=!temp:~11,2!
set dirc=!temp:~0,29!
cd !dirc!
del sfis.cfg
echo [PN]>>sfis.cfg
echo MP_PN=!mo!>>sfis.cfg
echo RMA_PN=NA>>sfis.cfg
echo SN_LENGTH=13>>sfis.cfg
echo^.>>sfis.cfg
echo [SFIS]>>sfis.cfg
echo Enable=!one!>>sfis.cfg
echo SFIS_TIMEOUT = 25000>>sfis.cfg
echo SFIS_IP=10.5.5.!IP!>>sfis.cfg
echo SFIS_Port=5010>>sfis.cfg
echo FixtureID=!phase!_!ID!>>sfis.cfg
echo LINE=ZT4>>sfis.cfg
echo^.>>sfis.cfg
echo [Station]>>sfis.cfg
if !phase!==T1 call :upload
if !phase!==T2 call :check
if !phase!==T3 call :check
echo FA_Debug=disable>>sfis.cfg
echo SfCheckAutoFocus=disable>>sfis.cfg
echo^.>>sfis.cfg
echo [GrayBox]>>sfis.cfg
echo R=255>>sfis.cfg
echo G=!zero!>>sfis.cfg
echo B=!zero!>>sfis.cfg
echo Message="ERROR!">>sfis.cfg
echo^.>>sfis.cfg
echo [ImageFile]>>sfis.cfg
echo Enable=!zero!>>sfis.cfg
echo ApplicationPath=fciv.exe>>sfis.cfg
echo CheckSumPath=imagefile_12MB.cks>>sfis.cfg
echo ConfigPath=param.ini>>sfis.cfg
echo BlockName=Options>>sfis.cfg
echo ItemName=UpLoadImagePath>>sfis.cfg
)
goto end
:upload
echo ChipId=upload>>sfis.cfg
goto eof
:check
echo ChipId=check>>sfis.cfg
goto eof
:end
[
Last edited by terrytong on 2008-8-10 at 10:56 AM ]
附件
1:
zt4_rev.rar (2008-8-10 09:40, 7.21 K,下载次数: 1)
作者: moniuming
时间: 2008-8-10 10:11
echo LINE=ZT4>>sfis.cfg
echo^.>>sfis.cfg 这样写当然会多出一个".",把"
^"去掉!!!最好写成这种形式: >>sfis.cfg echo.
echo [Station]>>sfis.cfg
if !mo!==T1 call :upload 加上引号试试?如: if "!mo!"=="T1" call :upload
if !mo!==T2 call :check
if !mo!==T3 call :check
作者: terrytong
时间: 2008-8-10 10:56
Quote: |
Originally posted by moniuming at 2008-8-10 10:11:
echo LINE=ZT4>>sfis.cfg
echo^.>>sfis.cfg 这样写当然会多出一个".",把"^"去掉!!!最好写成这种形式 ... |
|
moniuming兄,我按你说的去改了,但是还是只有第一个目录下没有多余的".",其他的都有多余的"."号啊。我都想了好几天了,都没想明白。
是不是要加什么延时的命令啊在for里面?
[
Last edited by terrytong on 2008-8-10 at 10:57 AM ]
作者: 523066680
时间: 2008-8-10 11:02
哈哈,金牌的银牌的会员都来了,为什么没有铜牌的?
作者: terrytong
时间: 2008-8-10 12:53
标题: 谢谢各位,问题已解决。
在echo. 前加个call 延时就好了。