Put the cursor at the start of the first line of the file. Use menu => Edit => Column editor. Select "Number to insert", Initial number = 1, increase by = 1, leave Repeat empty, select leading zeros. Click OK.
The file should now have line numbers, with leading zeroes, on each line. Count the number of digits added on the last line of the file. If the file has between 1000 and 9999 lines inclusive then there should be 4 (four) digits.
Open the search widow and select the Mark tab. In the find what field enter ^\d{4}.
. Change the 4 to the number of digits found on the last line of the file, if needed. That will mark any line that has something after the four leading digits. Select "regular expression" and "wrap around" and "bookmark line". Click on "mark all". Should now see all the lines except the blank lines having a blue circle near the left hand margin. Use menu => Search => bookmark => Remove bookmarked lines. The buffer should now only have entries for the blank lines.
Open the search and replace window. In the "find what" area enter ^\R0*
and in "replace with enter ,
(i.e. comma or comma-space). Select "regular expression" and "wrap around". Click on "replace all".
Now just need to remove leading zeroes on the first line and a possible trailing comma at the end of the text.
For an Excel method:
Asssuming each line of the file is in one row of a sheet. Insert a new column into the sheet. Put line numbers into the cells in that column. (I sometimes put 1
into cell A1 and the formula =A1+1
into the cell below. Then copy that cell into every cell below that until the last row of data in the sheet. Next, copy the whole column and do a paste special inserting values.)
Having got line numbers in a column of the sheet. Sort the sheet on the values in column B. That will bring all the non-empty lines to the top. The empty lines with their line numbers will be shown at the bottom of the sorted rows.