Is it possible to switch column lines?
-
Hello, my issue is:
line1
line2
line3
line4
line5I need to make it:
line5
line4
line3
line2
line1So, I have large column A to Z, with goal to make it Z to A
I hope someone can help me with this.
Thank you very much.
-
Seems like the Lua script I’ve written some days ago respectively the changed version of @dkeenan7 could be useful for you, have a look at this thread.
To use this solutin you need to install the LuaScript plugin, available via Plugins Admin.
-
@dinkumoil Hey,
Thank you very much for reaching out.
I followed your steps and successfully installed*/edited your script.
Sorry, I’m a complete newbie here, so I still don’t know how can I swap my lines.
Everything looks regular as it was before, could you please extra guide me here how to swap my lines?
Thanks once again.
-
Please read >>> this <<< comment of @dkeenan7 in the thread already mentioned. There he provided a step-by-step guide on how to install and use the script.
-
@X said in Is it possible to switch column lines?:
So, I have large column A to Z, with goal to make it Z to A
You could add line numbers (with leading zeros) to the start of each line, then order descending and then remove the line numbers just keeping the original line. So this does take a few steps.
- Have your cursor in the very first position in the file (line 1 column 1 before any characters)
- Under “Edit” menu, select “column editor”
- Select “text to insert” and type a single space (or other such character if line started with a space, perhaps &), click OK
- Again select first line, first position and this time select “number to insert”
- Initial number is 1, increase by also 1 and tick “leading zeros”, click OK.
- Select “Edit” menu again, and then “Line Operations”, then select “sort lines as integers descending”
At this point the lines have completed to “Z to A” switch. All that remains is to remove the characters and numbers we added initially. This requires a regex.
So uding “Search” menu , select “Replace”.
Find What:^\d+\s
(if you used & instead of space then type^\d+&
Replace with:empty field here
Click on “replace all” and the line numbers and “space” character are removed.
Terry
-
@dinkumoil said in Is it possible to switch column lines?:
Please read >>> this <<< comment of @dkeenan7 in the thread already mentioned. There he provided a step-by-step guide on how to install and use the script.
Hey buddy, my apologize for not seeing the upper part (above the script code) where it clearly says how to use it. However, this is not what I was looking for. At least, I still can’t figure out how to do my task at once. I can only rotate lines 1 by 1, can’t swap em to be Z to A.
If am wrong with this statement, please correct me if you don’t mind.
Check out Terry’s answer, just for the record. (like useful info)
-
@X said:
I can only rotate lines 1 by 1, can’t swap em to be Z to A.
Yes, thats true. I’m sorry if that doesn’t fit your needs.
-
@Terry-R Beautiful solution buddy. I really appreciate it.
Thank you very much!
@dinkumoil no problem mate, thanks for assisting me, I equally appreciate your help as well.
-
Hi, @x, @dinkumoil, @terry-r and All,
As @x, in its initial post, spoke about column A to Z, I first thought that he wanted to reverse all columns of a table in the opposite order !
If you need this kind of feature, no need for plugin or script ! Just regexes… as always ;-))
Let’s say you have a table, with
12
columns and the!
character as a delimiter, as below . Now, you would like to reverse, totally, the colum order !•--------------------------------------------------------------------------------------------• ! 12 ! 34 ! 123456 ! 789 ! 567890 ! a ! bcdefgh ! ABC ! abcdefg ! hijklmnopqqrstu ! vwxy ! z ! ! 12 ! 34 ! 123456 ! 789 ! 567890 ! a ! bcdefgh ! ABC ! abcdefg ! hijklmnopqqrstu ! vwxy ! z ! ! 12 ! 34 ! 123456 ! 789 ! 567890 ! a ! bcdefgh ! ABC ! abcdefg ! hijklmnopqqrstu ! vwxy ! z ! ! 12 ! 34 ! 123456 ! 789 ! 567890 ! a ! bcdefgh ! ABC ! abcdefg ! hijklmnopqqrstu ! vwxy ! z ! ! 12 ! 34 ! 123456 ! 789 ! 567890 ! a ! bcdefgh ! ABC ! abcdefg ! hijklmnopqqrstu ! vwxy ! z ! ! 12 ! 34 ! 123456 ! 789 ! 567890 ! a ! bcdefgh ! ABC ! abcdefg ! hijklmnopqqrstu ! vwxy ! z ! ! 12 ! 34 ! 123456 ! 789 ! 567890 ! a ! bcdefgh ! ABC ! abcdefg ! hijklmnopqqrstu ! vwxy ! z ! ! 12 ! 34 ! 123456 ! 789 ! 567890 ! a ! bcdefgh ! ABC ! abcdefg ! hijklmnopqqrstu ! vwxy ! z ! ! 12 ! 34 ! 123456 ! 789 ! 567890 ! a ! bcdefgh ! ABC ! abcdefg ! hijklmnopqqrstu ! vwxy ! z ! ! 12 ! 34 ! 123456 ! 789 ! 567890 ! a ! bcdefgh ! ABC ! abcdefg ! hijklmnopqqrstu ! vwxy ! z ! •--------------------------------------------------------------------------------------------•
If so,
-
Choose any dummy character, not presently used in your file : I chose the
#
character -
Paste, preferably, your table contents in a new tab
-
Open the Replace dialog (
Ctrl + H
) -
SEARCH
(?-s)^(?=.*!$)!(.+)!|#(.+)!(.+#)|(#)
-
REPLACE
(?1#\1#)(?2!\3\2#)?4!
-
Tick the
Wrap around
option -
Select the
Regular expression
search mode -
If
N
is the number of columns, click, exactly,N + 1
times on theReplace All
button ( or use theAlt + A
shotcut )
In this example,
N
is12
, so you need to click13
times on theReplace All
button !And you’ll get the expected text :
•--------------------------------------------------------------------------------------------• ! z ! vwxy ! hijklmnopqqrstu ! abcdefg ! ABC ! bcdefgh ! a ! 567890 ! 789 ! 123456 ! 34 ! 12 ! ! z ! vwxy ! hijklmnopqqrstu ! abcdefg ! ABC ! bcdefgh ! a ! 567890 ! 789 ! 123456 ! 34 ! 12 ! ! z ! vwxy ! hijklmnopqqrstu ! abcdefg ! ABC ! bcdefgh ! a ! 567890 ! 789 ! 123456 ! 34 ! 12 ! ! z ! vwxy ! hijklmnopqqrstu ! abcdefg ! ABC ! bcdefgh ! a ! 567890 ! 789 ! 123456 ! 34 ! 12 ! ! z ! vwxy ! hijklmnopqqrstu ! abcdefg ! ABC ! bcdefgh ! a ! 567890 ! 789 ! 123456 ! 34 ! 12 ! ! z ! vwxy ! hijklmnopqqrstu ! abcdefg ! ABC ! bcdefgh ! a ! 567890 ! 789 ! 123456 ! 34 ! 12 ! ! z ! vwxy ! hijklmnopqqrstu ! abcdefg ! ABC ! bcdefgh ! a ! 567890 ! 789 ! 123456 ! 34 ! 12 ! ! z ! vwxy ! hijklmnopqqrstu ! abcdefg ! ABC ! bcdefgh ! a ! 567890 ! 789 ! 123456 ! 34 ! 12 ! ! z ! vwxy ! hijklmnopqqrstu ! abcdefg ! ABC ! bcdefgh ! a ! 567890 ! 789 ! 123456 ! 34 ! 12 ! ! z ! vwxy ! hijklmnopqqrstu ! abcdefg ! ABC ! bcdefgh ! a ! 567890 ! 789 ! 123456 ! 34 ! 12 ! •--------------------------------------------------------------------------------------------•
Notes :
-
The regex contain
3
alternatives which do3
different search/replacement :-
First, it replaces the
!
delimiters, at beginning and end, of each row of the table, with the dummy#
character. This corresponds, both, in search and replacement, to the parts :-
SEARCH
^(?=.*!$)!(.+)!
( group1
) -
REPLACE
(?1#\1#)
-
-
Secondly, it swaps the
N - 1
first columns with the lastN
column. This corresponds, both, in search and replacement, to the parts, below, which are executedN - 1
times, repeatedly :-
SEARCH
#(.+)!(.+#)
( groups2
and3
) -
REPLACE
(?2!\3\2#)
-
-
Finally, it reverts any dummy
#
character to the initial!
character. This corresponds, both, in search and replacement, to the parts :-
SEARCH
^(#)
( group4
) -
REPLACE
?4!
-
-
Remark : You may repeat the process, again, for the
N + 1
following S/R actions. The nice thing is that, it provides, in our case,25
different column configurations ;-)), as described below :INITIAL table, with 3 ROWS of 12 COLUMNS ( = N ) •--------------------------------------------------------------------------------------------• ! 12 ! 34 ! 123456 ! 789 ! 567890 ! a ! bcdefgh ! ABC ! abcdefg ! hijklmnopqqrstu ! vwxy ! z ! ! 12 ! 34 ! 123456 ! 789 ! 567890 ! a ! bcdefgh ! ABC ! abcdefg ! hijklmnopqqrstu ! vwxy ! z ! ! 12 ! 34 ! 123456 ! 789 ! 567890 ! a ! bcdefgh ! ABC ! abcdefg ! hijklmnopqqrstu ! vwxy ! z ! •--------------------------------------------------------------------------------------------• After 5 consecutive 'REPLACE ALL' actions : - Columns, located BEFORE the FIRST #, are sorted in REVERSE order - Columns, located AFTER the FIRST #, are sorted in NORMAL order •--------------------------------------------------------------------------------------------• ! z ! vwxy ! hijklmnopqqrstu ! abcdefg # 12 ! 34 ! 123456 ! 789 ! 567890 ! a ! bcdefgh ! ABC # ! z ! vwxy ! hijklmnopqqrstu ! abcdefg # 12 ! 34 ! 123456 ! 789 ! 567890 ! a ! bcdefgh ! ABC # ! z ! vwxy ! hijklmnopqqrstu ! abcdefg # 12 ! 34 ! 123456 ! 789 ! 567890 ! a ! bcdefgh ! ABC # •--------------------------------------------------------------------------------------------• After 13 consecutive 'REPLACE ALL' actions ( N + 1 ) - ALL columns are sorted in REVERSE order •--------------------------------------------------------------------------------------------• ! z ! vwxy ! hijklmnopqqrstu ! abcdefg ! ABC ! bcdefgh ! a ! 567890 ! 789 ! 123456 ! 34 ! 12 ! ! z ! vwxy ! hijklmnopqqrstu ! abcdefg ! ABC ! bcdefgh ! a ! 567890 ! 789 ! 123456 ! 34 ! 12 ! ! z ! vwxy ! hijklmnopqqrstu ! abcdefg ! ABC ! bcdefgh ! a ! 567890 ! 789 ! 123456 ! 34 ! 12 ! •--------------------------------------------------------------------------------------------• After 21 consecutive 'REPLACE ALL' actions - Columns, located BEFORE the FIRST #, are sorted in NORMAL order - Columns, located AFTER the FIRST #, are sorted in REVERSE order •--------------------------------------------------------------------------------------------• ! 12 ! 34 ! 123456 ! 789 ! 567890 ! a ! bcdefgh # z ! vwxy ! hijklmnopqqrstu ! abcdefg ! ABC # ! 12 ! 34 ! 123456 ! 789 ! 567890 ! a ! bcdefgh # z ! vwxy ! hijklmnopqqrstu ! abcdefg ! ABC # ! 12 ! 34 ! 123456 ! 789 ! 567890 ! a ! bcdefgh # z ! vwxy ! hijklmnopqqrstu ! abcdefg ! ABC # •--------------------------------------------------------------------------------------------• After 26 consecutive 'REPLACE ALL' actions ( 2 x ( N + 1 ) ) - INITIAL table, again •--------------------------------------------------------------------------------------------• ! 12 ! 34 ! 123456 ! 789 ! 567890 ! a ! bcdefgh ! ABC ! abcdefg ! hijklmnopqqrstu ! vwxy ! z ! ! 12 ! 34 ! 123456 ! 789 ! 567890 ! a ! bcdefgh ! ABC ! abcdefg ! hijklmnopqqrstu ! vwxy ! z ! ! 12 ! 34 ! 123456 ! 789 ! 567890 ! a ! bcdefgh ! ABC ! abcdefg ! hijklmnopqqrstu ! vwxy ! z ! •--------------------------------------------------------------------------------------------•
However, for any configuration reached, with a number of clicks on the
Replace All
button, different fromK x ( N + 1 )
, you’ll need to perform, this elementary S/R, in the end :SEARCH
#
REPLACE
!
Best Regards
guy038
-
-
Although it’s too late to solve @X’s problem, I have added
Reverse Selections/Characters Ctrl+Alt+Shift+T
to @dinkumoil’s and my Transpose script. If you Alt-select a column, this command will reverse its rows. See
https://community.notepad-plus-plus.org/topic/18415/transpose-multiple-selections/15 -
If we are opening it up to scripting, here’s a Pythonscript reference for reversing lines: https://sourceforge.net/p/npppythonscript/discussion/1199074/thread/e61f36ec/
-
@dkeenan7 said in Is it possible to switch column lines?:
I have added
Reverse Selections/Characters Ctrl+Alt+Shift+T
to @dinkumoil’s and my Transpose script.I have to intervene, this script is far from being even partially my script! The honor is due to @dkeenan7. Thank you again!