1
这是我的例子输入txt文件内容:如何使用批处理脚本从多行txt文件中删除最后一个字符?
2 12 1 0 0 1
3 13 1 1 0 0
4 14 1 0 1 0
9 19 0 1 0 0
而且我想这个内容:
1`{SEQ=2,ACK=12,CTL=(SYN,on)} ++
1`{SEQ=3,ACK=13,CTL=(FIN,on)} ++
1`{SEQ=4,ACK=14,CTL=(RST,on)} ++
1`{SEQ=9,ACK=19,CTL=(FIN,off)}
所以我用批处理脚本:
@echo off
for /f "tokens=1-6 delims= " %%a in (file.txt) do (
IF %%c==1 IF %%d==0 IF %%e==0 IF %%f==0 ECHO 1^`^{SEQ=%%a,ACK=%%b,CTL=^(ACK,on^)^} ^+^+>> SEG1to2.txt
IF %%c==1 IF %%d==1 IF %%e==0 IF %%f==0 ECHO 1^`^{SEQ=%%a,ACK=%%b,CTL=^(FIN,on^)^} ^+^+>> SEG1to2.txt
IF %%c==1 IF %%d==0 IF %%e==1 IF %%f==0 ECHO 1^`^{SEQ=%%a,ACK=%%b,CTL=^(RST,on^)^} ^+^+>> SEG1to2.txt
IF %%c==1 IF %%d==0 IF %%e==0 IF %%f==1 ECHO 1^`^{SEQ=%%a,ACK=%%b,CTL=^(SYN,on^)^} ^+^+>> SEG1to2.txt
IF %%c==0 IF %%d==1 IF %%e==0 IF %%f==0 ECHO 1^`^{SEQ=%%a,ACK=%%b,CTL=^(FIN,off^)^} ^+^+>> SEG1to2.txt
IF %%c==0 IF %%d==0 IF %%e==1 IF %%f==0 ECHO 1^`^{SEQ=%%a,ACK=%%b,CTL=^(RST,off^)^} ^+^+>> SEG1to2.txt
IF %%c==0 IF %%d==0 IF %%e==0 IF %%f==1 ECHO 1^`^{SEQ=%%a,ACK=%%b,CTL=^(SYN,off^)^} ^+^+>> SEG1to2.txt
)
但当然我的得到这个输出:
1`{SEQ=2,ACK=12,CTL=(SYN,on)} ++
1`{SEQ=3,ACK=13,CTL=(FIN,on)} ++
1`{SEQ=4,ACK=14,CTL=(RST,on)} ++
1`{SEQ=9,ACK=19,CTL=(FIN,off)} ++
所以我需要删除最后两个“++”。如何才能做到这一点? 我不知道批处理文件中的哪个选项将被使用,以及多少次。
任何帮助,将不胜感激。谢谢!
[此](http://stackoverflow.com/questions/2505857/how-to-remove-the-first-and-last-character-from-a-file-using-batch-script)可能有帮助!但是这显示了如何删除第一个和最后一个字符,但我认为您可以修改它以删除最后两个字符,以便与@dbenham的回答相对应! – R2bEEaton 2016-06-12 14:33:10