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

Help with writing and playing macros

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

Postby Peter J. Veger » Fri Oct 30, 2009 8:34 am

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
Peter J. Veger
Newbie
 
Posts: 1
Joined: Fri Oct 30, 2009 8:18 am

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

Postby Mofi » Sat Oct 31, 2009 9:23 am

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.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 3937
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

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

Postby Mofi » Tue Dec 29, 2009 10:14 am

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 Downloads - Extras 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.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 3937
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna


Return to Macros