Sorting lines based on line number to reverse the order of the lines in a file

Sorting lines based on line number to reverse the order of the lines in a file

1

    Oct 30, 2009#1

    I just received from my bank a csv file.
    The order of the lines is such that the latest transaction is first; there are potentially multiple transactiob per day.

    Is it possible to reverse the order of the lines, so that the first line comes last, the second line penultimate, etc.?
    If this is not so easy, is there a possibility to insert the line number at the start of each line?

    Regards,
    Peter J. Veger

    6,686585
    Grand MasterGrand Master
    6,686585

      Re: Sorting lines based on line numbers to reverse the order of the lines in a file

      Oct 31, 2009#2

      That should be no problem. Set the cursor to top of the file and press Alt+C to enable the column mode.

      Now click on Column - Insert Number and simply press button OK because the default settings are already perfect for inserting "line numbers".

      Press again Alt+C to disable column mode.

      Next use File - Sort - Advanced Sort/Options and select Descending as sort order. Uncheck the option Remove Duplicates and Ignore Case and enter at Key 1 the value 1 for the start column and the value -1 for the end column. Run the sort now with button Sort which results on simply reversing the order of lines because of the line numbers at start of every line.

      Next enable again with Alt+C the column mode and use Column - Delete Columns to delete the line numbers at start of every line. The value you have to enter in the dialog depends on the number of lines which define the numbers of digits (= columns) of the line numbers.

      Finally press again Alt+C to disable column mode and save the file. You are done.

        Dec 29, 2009#3

        I wrote a macro to arrange all lines of a file or just the selected lines in reverse order. The macro Reverse Lines can be downloaded from the page user-submitted macros and is most useful for lists. On the referenced page you can download also a script written by IDM and improved by me to reverse the order of selected lines.