从文件中删除以空格开头的行,包括空行 [英] Remove lines from a file starting with a space, including empty lines

查看:76
本文介绍了从文件中删除以空格开头的行,包括空行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要删除txt文件中以空格开头的所有行(包括空行),我写

To delete all lines of a txt file that begins with a space (including empty lines), I write

    findstr /v /b /c:" " <%1>result.out.

的确,如果每行开头和空行都不再有空格,那么result.out文件就会为我解答.

Indeed, result.out file get answer for me if there is no longer both space at beginning of every line and empty line.

我所做的仍然将行标题保留为空,它还保留了我要放弃的空白行.最后,result.out输出必须具有连续的行,每行的开头始终包含一个文本.

What I have done still leaving lines header empty, it also preserves blank lines what i want to give up. Finally, the result.out output must have consecutive lines always containing a text at begining of each line.

请有人告诉我有什么问题以及如何解决?谢谢.

Please someone could tell me what it is faulty and how to fix that? Thanks.

推荐答案

如果要在要检查的空白中包含 Tab 字符,则必须使用批处理脚本.如果您尝试 Tab 或将 Tab 字符粘贴到控制台中,那么 cmd 控制台只会使您烦恼.但是 cmd .bat 文件中解释 Tab 没问题.

If you want to include Tab characters as part of the whitespace you want to check, you have to use a batch script. The cmd console simply makes an annoyed sound at you if you try to Tab or paste a Tab character into the console. But cmd interprets Tab in a .bat file no problem.

将其放入批处理文件中并运行,将 Space Tab 替换为实际的空间和制表符.

Put this into a batch file and run it, replacing Space and Tab with an actual space and tab.

findstr/r/v/c:"^ [ Space Tab ]"/c:"^ $""%〜1> result.out

第一个/c:在行的开头检查空格.第二个/c:检查空白行.两者都可以通过/v 开关忽略.

The first /c: checks for whitespace at the beginning of a line. The second /c: checks for blank lines. Both are omitted with the /v switch.

这篇关于从文件中删除以空格开头的行,包括空行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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