[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文本处理] 求助批处理通过关键字符拆分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

谢谢各位大大,感谢。

  1. 5,174.7137,1,001, 面,,3,,@
  2. 1,1,482492.368,415664.304
  3. 2,1,482469.182,415627.564
  4. 3,1,482489.587,415563.972
  5. 4,1,482491.284,415561.571
  6. 5,1,482494.570,415555.573
  7. 3,851.6603,2,002, 面,,2,,@
  8. 1,1,483942.849,417784.072
  9. 2,1,483941.546,417784.921
  10. 3,1,483941.745,417769.202
复制代码
以ANSI编码格式保存为1.txt
下载gawk( http://bcn.bathome.net/tool/4.1.0/gawk.exe
执行
  1. gawk "/, 面,/{++n}{print $0>\"xx-\"n\".txt\"}" 1.txt>con
复制代码
结果( xx-1.txt )
  1. 5,174.7137,1,001, 面,,3,,@
  2. 1,1,482492.368,415664.304
  3. 2,1,482469.182,415627.564
  4. 3,1,482489.587,415563.972
  5. 4,1,482491.284,415561.571
  6. 5,1,482494.570,415555.573
复制代码
结果( xx-2.txt )
  1. 3,851.6603,2,002, 面,,2,,@
  2. 1,1,483942.849,417784.072
  3. 2,1,483941.546,417784.921
  4. 3,1,483941.745,417769.202
复制代码

TOP

回复 2# hfxiang


    谢谢大大

TOP

  1. @echo off
  2. setlocal enabledelayedexpansion
  3. set /a "n=0"
  4. for /f "tokens=*" %%a in (1.txt) do (
  5.     echo "%%a" | findstr ",面," && ( set /a "n=n+1")
  6.     echo %%a>>xx-!n!.txt
  7. )
  8. pause
复制代码
bat小白,请多指教!谢谢!

TOP

回复 4# 77七


    大神,厉害啊,这个可以,是慢了一点,但是代码没有问题,感谢

TOP

返回列表