Move Line Up
-
Hello, my project manager wants me to move the “#DESCRIPTION” line above the “#SERVICE” line. Our master list contains several hundred entries. Can I highlight all “#DESCRIPTION” lines and move them above the “#SERVICE” line?
Thank you.
#SERVICE:4:8:1:6:0 #DESCRIPTION Angus #SERVICE:4:7:0:3:0: #DESCRIPTION Ayrshire #SERVICE:5:8:4:1:0 #DESCRIPTION Brown-Swiss #SERVICE:3:6:7:1:0 #DESCRIPTION Galloway #SERVICE:4:9:2:5:0 #DESCRIPTION Guernsey #SERVICE:6:4:7:8:0 #DESCRIPTION Hereford #SERVICE:2:7:4:1:0 #DESCRIPTION Holstein #SERVICE:6:4:2:9:0 #DESCRIPTION Piedmontese #SERVICE:3:6:3:1:0 #DESCRIPTION Scottish-Highland #SERVICE:4:4:9:3:0 #DESCRIPTION Shorthorn -
FIND =
(^#SERVICE.*)(\R)(^#DESCRIPTION.*)(\R?)
REPLACE =$3$2$1$2
SEARCH MODE =Regular ExpressionThis puts the
#SERVICEline in memory slot 1, the newline in memory slot 2, the#DESCRIPTIONin memory slot 3, and the second newline in slot 4. (But because files sometimes don’t end in a newline, I made it optional with the?The replacement uses slot 3, then 2, then 1, then 2 again, to swap the order of 1 and 3, and to make sure there’s always a newline, whether it was the last line of the file or not.
-—
Useful References
-
Yes that works very well. Thank you so much. So the $ is a “backreference” in replacement strings when using regular expressions in the Find and Replace dialog?
Barry
-
Ok I see the “Useful References” link under Regex Special Characters for Searches, that explains it pretty well.
Thanks again.
Barry
-
Hello, @barry-lort, @peterjones and All,
@barry-lort, here is an other method to solve your problem !
Let’s suppose that your file contains
100lines, so50lines beginning with#SERVICEand50lines beginning with#DESCRIPTION, as below :#SERVICE:4:8:1:6:0 #DESCRIPTION Angus #SERVICE:4:7:0:3:0: #DESCRIPTION Ayrshire #SERVICE:5:8:4:1:0 #DESCRIPTION Brown-Swiss #SERVICE:3:6:7:1:0 #DESCRIPTION Galloway #SERVICE:4:9:2:5:0 #DESCRIPTION Guernsey #SERVICE:6:4:7:8:0 #DESCRIPTION Hereford #SERVICE:2:7:4:1:0 #DESCRIPTION Holstein #SERVICE:6:4:2:9:0 #DESCRIPTION Piedmontese #SERVICE:3:6:3:1:0 #DESCRIPTION Scottish-Highland #SERVICE:4:4:9:3:0 #DESCRIPTION Shorthorn #SERVICE:4:8:1:6:0 #DESCRIPTION Angus #SERVICE:4:7:0:3:0: #DESCRIPTION Ayrshire #SERVICE:5:8:4:1:0 #DESCRIPTION Brown-Swiss #SERVICE:3:6:7:1:0 #DESCRIPTION Galloway #SERVICE:4:9:2:5:0 #DESCRIPTION Guernsey #SERVICE:6:4:7:8:0 #DESCRIPTION Hereford #SERVICE:2:7:4:1:0 #DESCRIPTION Holstein #SERVICE:6:4:2:9:0 #DESCRIPTION Piedmontese #SERVICE:3:6:3:1:0 #DESCRIPTION Scottish-Highland #SERVICE:4:4:9:3:0 #DESCRIPTION Shorthorn #SERVICE:4:8:1:6:0 #DESCRIPTION Angus #SERVICE:4:7:0:3:0: #DESCRIPTION Ayrshire #SERVICE:5:8:4:1:0 #DESCRIPTION Brown-Swiss #SERVICE:3:6:7:1:0 #DESCRIPTION Galloway #SERVICE:4:9:2:5:0 #DESCRIPTION Guernsey #SERVICE:6:4:7:8:0 #DESCRIPTION Hereford #SERVICE:2:7:4:1:0 #DESCRIPTION Holstein #SERVICE:6:4:2:9:0 #DESCRIPTION Piedmontese #SERVICE:3:6:3:1:0 #DESCRIPTION Scottish-Highland #SERVICE:4:4:9:3:0 #DESCRIPTION Shorthorn #SERVICE:4:8:1:6:0 #DESCRIPTION Angus #SERVICE:4:7:0:3:0: #DESCRIPTION Ayrshire #SERVICE:5:8:4:1:0 #DESCRIPTION Brown-Swiss #SERVICE:3:6:7:1:0 #DESCRIPTION Galloway #SERVICE:4:9:2:5:0 #DESCRIPTION Guernsey #SERVICE:6:4:7:8:0 #DESCRIPTION Hereford #SERVICE:2:7:4:1:0 #DESCRIPTION Holstein #SERVICE:6:4:2:9:0 #DESCRIPTION Piedmontese #SERVICE:3:6:3:1:0 #DESCRIPTION Scottish-Highland #SERVICE:4:4:9:3:0 #DESCRIPTION Shorthorn #SERVICE:4:8:1:6:0 #DESCRIPTION Angus #SERVICE:4:7:0:3:0: #DESCRIPTION Ayrshire #SERVICE:5:8:4:1:0 #DESCRIPTION Brown-Swiss #SERVICE:3:6:7:1:0 #DESCRIPTION Galloway #SERVICE:4:9:2:5:0 #DESCRIPTION Guernsey #SERVICE:6:4:7:8:0 #DESCRIPTION Hereford #SERVICE:2:7:4:1:0 #DESCRIPTION Holstein #SERVICE:6:4:2:9:0 #DESCRIPTION Piedmontese #SERVICE:3:6:3:1:0 #DESCRIPTION Scottish-Highland #SERVICE:4:4:9:3:0 #DESCRIPTION Shorthorn
Now, just follow this road map :
-
Select any string
#SERVICE -
Run the
Edit > Multi-select All > Match Case Onlyoption
=> All strings
#SERVICEshould have been selected-
Use the
Shift + Endshortcut to extend the selection to the end of each line -
Use the
Ctrl + Xshortcut to delete these lines and place them in the clipboard -
Hit two times on the
Down arrowkey
=> Each cursor/caret should had been moved two lines under
-
Use the
Ctrl + Vshortcut to recopy all#SERVICElines to their new location -
Finally, hit the
ESCkey to clear the current multi-selection
Voila !
Best Regards,
guy038
P.S. :
We could use the multi-selection of all
#DESCRIPTIONlines, either ! But, in that case, you need to :-
Add an
emptyline at the very beginning of your file -
Hit two times on the
Up arrowkey, right before the pasting operation
P.P.S. :
A similar regex S/R could be :
FIND
(?-s)^(.+\R)(.+(\R)?)REPLACE
$2(?3:\r\n)$1Note that the conditional replacement
(?3:\r\n)manages the case where your last#DESCRIPTIONline would not end with a line-break ! -
-
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login