text1.txt
20150716
aaaa
bbbb
cccc
dddd
END
我想删除20150716,然后整个文本将向上移动1行并删除最后一个特定字符串“END”。 最后,保存为名为text1_copy.txt的新文件。 然后,文件变为:
aaaa
bbbb
cccc
dddd
有什么想法吗?感谢。
答案 0 :(得分:3)
这只是跳过第一行而不写最后一行。
P(j)
答案 1 :(得分:2)
检查tailhead.bat,这样您就可以按数字显示文件中的行:
call tailhead.bat -file="text1.txt" -begin=2 -end=-2 >newfile.txt
答案 2 :(得分:1)
我为这个名为cut.bat
创建了一个简单的.bat文件set file=%~1
set outfile=%~2
if exist %file% goto Main
:error
echo Invalid File!
goto end
:main
for /F "delims=" %%j in ('more +1 %file%') do (
if defined row echo.!row!>> %outfile%
set row=%%j
)
:end
你要做的就是
调用cut.bat test1.txt output.txt
答案 3 :(得分:1)
more +1 t.txt|findstr /vX "END" > text1_copy.txt
其中more +1
跳过第一行
并findstr /vx "END"
删除每一行,正好是END
(ENDING
或THE END
之类的行不会被删除)
答案 4 :(得分:0)
对于你的情况,为了好玩,你可以在3个纯粹和简单的DOS命令
findstr /V "20150716" input.txt > output.1.txt
findstr /V "END" output.1.txt > output.2.txt
copy output.2.txt input.txt
有关信息,请使用"(20150716 | END)"使用FINDSTR DOS命令的Reges似乎无法使用/ V选项!
但在安装GOW或CYGWIN之后使用SED命令是最重要的
sed -i "1d;$d" input.txt
,其中
-i
选项直接在输入文件中强制替换1d
请求删除第一行$d
请求删除最后一行您可以从Gow GITHUB
下载GOW