How to delete the first empty line in multiple files?

I have thousands of text files with an empty first line. Is it possible to immediately delete this line in all files?

enter image description here

+4
source share
2 answers

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 in your directory.

+1
source

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, regardless of multi-line settings.

Note. This regex is somewhat more general than requested by the OP. It will remove any number of consecutive source blank lines terminated with any line break sequence ( \r\n , \r or \n ). Nothing is worse than changing thousands of files, only to find later that the pair has a different sequence of line breaks or has several original empty lines.

Alternative:

Another regex that works:

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

Explanation:

In this case, a negative look-behind, (?<!) to make sure that the character does not exist before the sequence CR and LF s.

Note. For this to work, check the box . matches newline . matches newline .

+1
source

Source: https://habr.com/ru/post/1483128/


All Articles