标题: [文本处理] 求助批处理通过关键字符拆分txt [打印本页]
作者: bryant2009 时间: 2022-12-9 10:25 标题: 求助批处理通过关键字符拆分txt
单一个txt,例如,通关键字“,面,”拆分成n个txt,
根据拆分前后顺序,自动排序。
例子
拆分之前:
5,174.7137,1,001,面,,3,,@
1,1,482492.368,415664.304
2,1,482469.182,415627.564
3,1,482489.587,415563.972
4,1,482491.284,415561.571
5,1,482494.570,415555.573
3,851.6603,2,002,面,,2,,@
1,1,483942.849,417784.072
2,1,483941.546,417784.921
3,1,483941.745,417769.202
拆分之后:
xx-1.txt
5,174.7137,1,001,面,,3,,@
1,1,482492.368,415664.304
2,1,482469.182,415627.564
3,1,482489.587,415563.972
4,1,482491.284,415561.571
5,1,482494.570,415555.573
xx-2.txt
3,851.6603,2,002,面,,2,,@
1,1,483942.849,417784.072
2,1,483941.546,417784.921
3,1,483941.745,417769.202
谢谢各位大大,感谢。
作者: hfxiang 时间: 2022-12-9 10:38
将- 5,174.7137,1,001, 面,,3,,@
- 1,1,482492.368,415664.304
- 2,1,482469.182,415627.564
- 3,1,482489.587,415563.972
- 4,1,482491.284,415561.571
- 5,1,482494.570,415555.573
- 3,851.6603,2,002, 面,,2,,@
- 1,1,483942.849,417784.072
- 2,1,483941.546,417784.921
- 3,1,483941.745,417769.202
复制代码
以ANSI编码格式保存为1.txt
下载gawk( http://bcn.bathome.net/tool/4.1.0/gawk.exe )
执行- gawk "/, 面,/{++n}{print $0>\"xx-\"n\".txt\"}" 1.txt>con
复制代码
结果( xx-1.txt )- 5,174.7137,1,001, 面,,3,,@
- 1,1,482492.368,415664.304
- 2,1,482469.182,415627.564
- 3,1,482489.587,415563.972
- 4,1,482491.284,415561.571
- 5,1,482494.570,415555.573
复制代码
结果( xx-2.txt )- 3,851.6603,2,002, 面,,2,,@
- 1,1,483942.849,417784.072
- 2,1,483941.546,417784.921
- 3,1,483941.745,417769.202
复制代码
作者: bryant2009 时间: 2022-12-9 11:18
回复 2# hfxiang
谢谢大大
作者: 77七 时间: 2022-12-9 12:16
- @echo off
- setlocal enabledelayedexpansion
- set /a "n=0"
- for /f "tokens=*" %%a in (1.txt) do (
- echo "%%a" | findstr ",面," && ( set /a "n=n+1")
- echo %%a>>xx-!n!.txt
- )
- pause
复制代码
作者: bryant2009 时间: 2022-12-9 15:28
回复 4# 77七
大神,厉害啊,这个可以,是慢了一点,但是代码没有问题,感谢
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |