Board logo

标题: [文本处理] [已解决]求助BAT批量合并同一目录下的所有txt文本,去除重复,去除空行 [打印本页]

作者: gater    时间: 2015-3-27 17:49     标题: [已解决]求助BAT批量合并同一目录下的所有txt文本,去除重复,去除空行

求助批量合并同一目录下的所有txt文本,去除重复,去除空行!

比如:
a.txt内容
aaa

bbb

33333.txt内容
bbb
ccc

求一批处理,使运行后生成c.txt
c.txt内容
aaa
bbb
ccc
主要是去掉重复的内容,去掉空行,
作者: pcl_test    时间: 2015-3-27 18:10

本帖最后由 pcl_test 于 2015-3-29 18:33 编辑

回复 1# gater
  1. @echo off
  2. for /f "delims=" %%a in ('dir /a-d /b /on *.txt') do (
  3. for /f "delims=" %%b in ('type "%%a"') do (
  4. if not defined %%b set %%b=Def & >>$ echo,%%b
  5. )
  6. )
  7. move $ "合并.txt"
  8. pause
复制代码

作者: DAIC    时间: 2015-3-27 18:27

  1. @echo off
  2. (for /f "delims=" %%a in ('dir /b /a-d *.txt') do (
  3.     for /f "delims=" %%b in ('type "%%a"') do (
  4.         if not defined %%b (
  5.             set %%b=1
  6.             echo,%%b
  7.         )
  8.     )
  9. ))>合并.txt
复制代码

作者: CrLf    时间: 2015-3-27 18:44

  1. @echo off
  2. (for /f "delims=" %%a in ('type *.txt' 2^>nul) do (
  3. if not defined %%b (
  4. set %%b=1
  5. echo,%%b
  6. )
  7. ))>合并.txt
复制代码

作者: 慕夜蓝化    时间: 2015-3-28 10:58

  1. @echo off
  2. setlocal enabledelayedexpansion
  3. (for %%i in (*.txt) do (
  4.     for /f "usebackq delims=" %%a in ("%%i") do (
  5.     echo,%%a
  6.     )
  7. )) >%temp%\$
  8. for /f "delims=" %%i in (%temp%\$) do (
  9. call :find "%%i"
  10. )
  11. pause
  12. :find
  13. find "%~1" "$1" >nul 2>nul||echo,%~1>>$1.txt&&goto :eof
  14. goto :eof
复制代码

作者: 慕夜蓝化    时间: 2015-3-28 11:07

  1. @echo off
  2. setlocal enabledelayedexpansion
  3. (for %%i in (*.txt) do (
  4.     for /f "usebackq delims=" %%a in ("%%i") do (
  5.     if not defined %%a set "%%a=."&echo,%%a
  6. )
  7. )) >$
  8. move /y $ result.txt >nul
  9. pause
复制代码

作者: pcl_test    时间: 2015-3-28 15:41

回复 1# gater
问题得到解决后请在标题最前面注明[已解决]
http://www.bathome.net/thread-3473-1-1.html
作者: gater    时间: 2015-3-28 16:51

本帖最后由 gater 于 2015-3-28 17:26 编辑

回复 2# pcl_test


@echo off
for /f "delims=" %%a in ('dir /a-d /b /on *.txt') do >>"合并.txt" type "%%a"
for /f "delims=" %%b in ('type "合并.txt"') do (
if not defined %%b set %%b=Def & >>$ echo,%%b
)
move $ "合并.txt"
pause
提示系统找不到指定文件!!有重复  代码需要优化,可以用!!
作者: gater    时间: 2015-3-28 17:25

回复 3# DAIC


和二楼一样的测试文本, 大量数据出现丢失~~
作者: gater    时间: 2015-3-28 17:28

回复 4# CrLf


和 2、3楼一样的测试数据,合并文本没有数据~~
作者: gater    时间: 2015-3-28 17:33

回复 6# 慕夜蓝化


出现了和3楼一样的情况,数据丢失!
作者: gater    时间: 2015-3-28 17:33

采纳2楼的代码!!
作者: DAIC    时间: 2015-3-28 21:45

回复 9# gater


    能否把你的数据发出来,我想看看哪些会丢掉。
作者: yiwuyun    时间: 2015-3-29 09:05

  1. if ($true){}# == ($true){}# goto ___yiwuyun
  2. <#
  3. :___yiwuyun
  4. @echo off&setlocal&cls
  5. (echo $strPath="%~dp0"&type "%~f0")|powershell -command -
  6. pause
  7. exit/b 0
  8. #>
  9. gc -path ($strPath+"*.txt")|sort  -unique
  10. <#end#>
复制代码

作者: gater    时间: 2015-3-29 15:19

本帖最后由 gater 于 2015-3-29 15:21 编辑

回复 13# DAIC

源数据有点大,附件不能上传,下载地址:http://43.252.160.140:8009/广东坐标.zip




欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2