Printing a file backwards

Paul Ruel paul at sesame.UUCP
Tue Oct 8 16:59:00 AEST 1985


My feed's been unreliable recently, so I hope I'm not too untimely wih this
followup...In keeping with the UN*X philosophy of using big complicated tools
to solve small, inconsequential problems (:->), I suggest that you do the
following to reverse lines in a file:

	1)  Edit the file using `vi';
	2)  `O'pen a line and type the following:

		:1m'a^[-ma

	    Note that the `^[' means an ESCape;
	3)  Delete this line into macro `a' by typing `"add' when positioned
	    on the just created line (the `' are NOT typed);
	4)  Move your cursor to some line in the file and mark that line
	    as line `a' by typing `ma';
	5)  Type `@a' and *poof* all the lines in the file (above the marked
	    line) will be reversed!

The reversing process is terminated with a message from `vi' which reads:

	Move to a moved line

which, despite its appearance, _means_: `The reversing is done'.

By the way, this works on my 3b2/300 `vi', I hope it works on yours.  `vi'
macro experimentation is a _lot_ safer than playing `hack' on your employer's
dime.  Yes, you _can_ get `vi' stuck in loops, etc.  I've got a number of
visual display time wasters written in `vi' macros.



More information about the Comp.sources.unix mailing list