标题: [文本处理] 批处理如何删除txt文本末尾最后的3个字符/几个字符 [打印本页]
作者: yujiaphf 时间: 2016-10-16 06:04 标题: 批处理如何删除txt文本末尾最后的3个字符/几个字符
本帖最后由 pcl_test 于 2017-3-19 04:42 编辑
如何删除txt文件中最后3个字符
作者: pcl_test 时间: 2016-10-16 06:48
- rem win7及以上系统运行
- powershell -c "[IO.File]::ReadAllText('测试.txt',[Text.Encoding]::Default) -replace '[^\r\n]{3}[\r\n]*$'"
- pause
复制代码
作者: yujiaphf 时间: 2016-10-16 08:37
XP系统的,好像不好用
作者: happy886rr 时间: 2016-10-16 09:48
回复 3# yujiaphf
兼容各种特殊字符,把%~f0改成你的文件名即可- @echo off
- set FileName="%~f0"
-
- for /f "tokens=1-2 delims=:" %%a in ('findstr /n .* %FileName%') do (set i=%%a)
- (
- for /l %%j in (1,1,%i%) do (
- set "str="
- set/p str=
- setlocal enabledelayedexpansion
- if %%j equ %i% (set "str=!str:~0,-3!")
- echo;!str!
- endlocal
- )
- )<%FileName%
- set/p=
- 留意尾部要消失的!*^ ,#%!*^
复制代码
作者: bailong360 时间: 2016-10-16 10:53
- @mshta http://bathome.net/s/hta/ type('test.txt').replace(/...$/, '')|more >new.txt
复制代码
作者: CrLf 时间: 2016-10-17 09:37
回复 5# bailong360
重定向不需要 more,可以直接 >new.txt
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |