问题
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