How do I flip the line orders of a document with 500+ lines?

3

Line 1
Line 2
Line 3
Line 4
Line 5

should become

Line 5
Line 4
Line 3
Line 2
Line 1

I need a notepad script to do this.

Manish

Posted 2011-11-02T16:31:40.920

Reputation: 31

Notepad is not scriptable, is it? – user1686 – 2011-12-12T18:32:14.960

Answers

7

If you have Perl installed you can use

perl -e 'print reverse <> ' filename > newfile

As in

$ cat file.txt
line 1
line 2
line 3
line 4
line 5
$ perl -e 'print reverse <>' file.txt > new.txt
$ cat new.txt
line 5
line 4
line 3
line 2
line 1

(its the same on Windows but use type instead of cat and use double-quotes (") in the perl command.)

You have tagged your question "notepad" and mentioned "notepad" in the text. If you want a solution using "notepad++", you should edit the question accordingly.

RedGrittyBrick

Posted 2011-11-02T16:31:40.920

Reputation: 70 632

4

This is a three step process in Notepad++ using TextFX.

  1. Select the entire document (ctrl+A) (or the section you want to be reversed), and from the TextFX menu, select TextFX Tools -> Insert Line Numbers.
  2. From the TextFX menu, make sure that TextFX Tools -> +Sort ascending is unchecked and then select TextFX Tools -> Sort lines case sensitive (at column). This will reverse the order of the lines.
  3. From the TextFX menu, select TextFX Tools -> Delete Line Numbers or First Word, and you're done.

The Notepad app that ships with Windows is pretty much useless. There are many alternatives, but I prefer Notepad++.

MBraedley

Posted 2011-11-02T16:31:40.920

Reputation: 2 712

3

Notepad, unless you mean some other than the one that comes with Windows OS, is not scriptable. Were you to use Vim, it would be simply

:g/^/m0

Rook

Posted 2011-11-02T16:31:40.920

Reputation: 21 622

0

You could try tac which reverses line by line

tac filename

Sairam

Posted 2011-11-02T16:31:40.920

Reputation: 232

0

If you were after a ready made script, the script center has one contributed by the community (i.e. not written by Microsoft)

http://gallery.technet.microsoft.com/scriptcenter/55ba15dc-9933-4c9d-a2b0-524453a66343

maweeras

Posted 2011-11-02T16:31:40.920

Reputation: 596