Windows批处理:如何删除所有空白(或空)行 [英] Windows Batch: How remove all blank (or empty) lines

查看:604
本文介绍了Windows批处理:如何删除所有空白(或空)行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Windows批处理程序从文本文件中删除所有空白行.

I am trying to remove all blank lines from a text file using a Windows batch program.

我知道最简单的方法是通过正则表达式和sed命令ba sh :

I know the simplest way do achieving this is bash is via regular expressions and the sed command:

sed -i "/^$/d" test.txt

问题:Windows批处理是否具有类似的简单方法,用于从文本文件中删除所有行?否则,什么是最简单的方法来实现这一目标?

Question: Does Windows batch have an similar simple method for removing all lines from a text file? Otherwise, what is the simplest method to achieving this?

注意:我正在运行此批处理脚本来设置新的Windows计算机供客户使用,因此最好无需安装其他程序(然后安装)即可实现这一点-理想情况下,我将只使用标准"批处理库.

Note: I'm running this batch script to setup new Windows computers for customers to use, and so preferably no additional programs need to be installed (and then unistalled) to achieve this - ideally, I'll just be using the "standard" batch library.

推荐答案

对于/f,不处理空行:

For /f does not process empty lines:

for /f "usebackq tokens=* delims=" %%a in ("test.txt") do (echo(%%a)>>~.txt
move /y  ~.txt "test.txt"

这篇关于Windows批处理:如何删除所有空白(或空)行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆