How to delete first blank row in multiple files?

拟墨画扇 提交于 2019-12-23 12:51:34

问题


I have thousands of text file with empty first row. Is it possible to delete this row in all files at once?


回答1:


You need a bat script like this

@echo off
for %%i in (*.txt) do (
more +1 "%%~fi">>temp
del "%%~fi"
ren temp "%%~nxi"
)

Save the above code as something.bat and run it at your directory.




回答2:


This will work using Notepad++ (tested with version 6.2.3):

\A[\r\n]+

Explanation:

\A and \Z always match the beginning and end of the entire file, irrespective of the multiline setting.

Note: This regex is slightly more general than the OP asked. It will remove any number of consecutive initial blank rows terminated with any line break sequence (\r\n, \r or \n). Nothing is worse than changing thousands of files only to find later that a couple have a different line break sequence or have multiple initial blank lines.

Alternative:

Another regex that works is:

(?<!.)[\r\n]+

Explanation:

This uses negative look-behind, (?<!), to make sure no character exists before the sequence of CRs and LFs.

Note: You must tick the . matches newline check box for this to work.



来源:https://stackoverflow.com/questions/16790431/how-to-delete-first-blank-row-in-multiple-files

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!