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

[文件操作] [已解决]批处理如何删除回车的空行?

批处理删除回车的空行?如何写:
原文件:a.txt 共3行,第二行与第三行为空行,内容如下:
  1. `~@#$&*()_+-='\,./:|<>?
复制代码
我要删除第二行与第三行,保留第一行的
  1. `~@#$&*()_+-='\,./:|<>?
复制代码
或者有没有其它的外部命令可实现,如果有希望同时提供外部程序与命令,谢谢!

[ 本帖最后由 ZULGMG 于 2010-5-16 00:13 编辑 ]
1

评分人数

    • Batcher: 感谢主动给标题标注[已解决]字样PB + 2

@echo off
for /f "eol= " %%i in (a.txt) do echo %%i >>aa.txt
pause

不知道可不可以帮你
1

评分人数

TOP

  1. @echo off
  2. (for /F "delims=" %%a in (a.txt) do (
  3. setlocal enabledelayedexpansion
  4. set a=%%a
  5. set/p"=!a!"<nul
  6. endlocal))>a_.txt
复制代码
也可以用sed等第三方命令:
  1. fr a.txt -ric:\r\n -t:
复制代码
1

评分人数

寒夜孤星:在没有说明的情况下,本人所有代码均运行在 XP SP3 下 (有问题请发贴,QQ临时会话已关闭)

TOP

感谢“寒夜孤星”及“小波子”,已解决……谢谢
  1. fr a.txt -ric:\r\n -t:
复制代码
是嘛意思?sed.exe 下载了,但看的不是很明白,能否再说说

  1. X:\>sed /?
  2. sed: -e expression #1, char 2: Unterminated address regex
复制代码

[ 本帖最后由 ZULGMG 于 2010-5-14 15:14 编辑 ]

TOP

看到了:
  1. sed: invalid option -- t
  2. Usage: sed [OPTION]... {script-only-if-no-other-script} [input-file]...
  3.   -n, --quiet, --silent
  4.                  suppress automatic printing of pattern space
  5.   -e script, --expression=script
  6.                  add the script to the commands to be executed
  7.   -f script-file, --file=script-file
  8.                  add the contents of script-file to the commands to be executed
  9.   -i[suffix], --in-place[=suffix]
  10.                  edit files in place (makes backup if extension supplied)
  11.   -l N, --line-length=N
  12.                  specify the desired line-wrap length for the `l' command
  13.   -r, --regexp-extended
  14.                  use extended regular expressions in the script.
  15.   -s, --separate
  16.                  consider files as separate rather than as a single continuous
  17.                  long stream.
  18.   --text     switch to text mode
  19.   -u, --unbuffered
  20.                  load minimal amounts of data from the input files and flush
  21.                  the output buffers more often
  22.       --help     display this help and exit
  23.   -V, --version  output version information and exit
  24. If no -e, --expression, -f, or --file option is given, then the first
  25. non-option argument is taken as the sed script to interpret.  All
  26. remaining arguments are names of input files; if no input files are
  27. specified, then the standard input is read.
  28. E-mail bug reports to: bonzini@gnu.org .
  29. Be sure to include the word ``sed'' somewhere in the ``Subject:'' field.
复制代码


谢谢各位兄弟!

TOP

fr和sed一样,都是第三方命令程序,fr下载地址:http://ishare.iask.sina.com.cn/f/7088512.html
寒夜孤星:在没有说明的情况下,本人所有代码均运行在 XP SP3 下 (有问题请发贴,QQ临时会话已关闭)

TOP

谢谢兄弟,下了,今天用上兄弟那个处理了,所以没看仔细那第三方工具,第三方工具也不错,支持特殊字符,谢谢兄弟热心关注!

TOP

请将标题前加 [已解决]
寒夜孤星:在没有说明的情况下,本人所有代码均运行在 XP SP3 下 (有问题请发贴,QQ临时会话已关闭)

TOP

我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

  1. sed -i "/^$/d" a.txt
复制代码
1

评分人数

TOP

  1. gawk "$0" a.txt >b.txt
复制代码

TOP

感谢上面热心的朋友,学习到了更多知识……谢谢!

TOP

返回列表