How to mass shift and paste (see attached)
-
See attached. This is one example of the many instances this issue occurs in my data set. For ocm00542515, I need all of the associated numbers below it (69996643, 69996644, etc.) to shift to the right column, and then I need “ocm00542515” to be copied and pasted all the way down in the left column until I reach the next “ocm #”. This is a very large data set, and this issue occurs many times throughout, so any way to have this change occur for all instances would be perfect.
-
Hello, @sam-keller and All,
Your goal could certainly be realized easily with a script language , like
Python
orLua
As for me, I think it can be solved with regular expressions, too !
So, given your INPUT text, below :
0cm00542421 70559817 0cm00542424 69948854 69948855 ocm00542436 71133882 ocm00542442 71139953 ocm00542459 69705562 ocm00542468 71149982 ocm00542470 69787610 ocm00542476 70958115 ocm00542488 71150286 71150287 ocm00542497 70157118 ocm00542498 71126285 ocm00542502 69801834 ocm00542515 69996642 69996643 69996644 69996645 69996646 69996647 69996648 69996649 69996650 69996651 69996652 69996653 69996654 69996655 69996656 69996657 69996658 69996659 0cm00542526 69961542 0cm00542538 69828403 0cm00542548 71140062 0cm00542559 71139834 0cm00542582 71140169 71140170 0cm00542584 71140175 ocm00542598 69741270
With the first regex S/R, below, it grasps, all together, the last line with
20
characters containing the part to duplicate as well as all the lines of8
characters which follow and rewrites, first, the entire contents followed with an additional line, beginning with a#
char and then the0cm........
part to duplicateSEARCH
(?-s)^(.{11}).+\R(.{8}\R)+
REPLACE
$0#$1\r\n
Don’t forget to select the
regular expression
mode and theWrap around
optionYou’ll get this temporary OUTPUT text, below :
0cm00542421 70559817 0cm00542424 69948854 69948855 #0cm00542424 ocm00542436 71133882 ocm00542442 71139953 ocm00542459 69705562 ocm00542468 71149982 ocm00542470 69787610 ocm00542476 70958115 ocm00542488 71150286 71150287 #ocm00542488 ocm00542497 70157118 ocm00542498 71126285 ocm00542502 69801834 ocm00542515 69996642 69996643 69996644 69996645 69996646 69996647 69996648 69996649 69996650 69996651 69996652 69996653 69996654 69996655 69996656 69996657 69996658 69996659 #ocm00542515 0cm00542526 69961542 0cm00542538 69828403 0cm00542548 71140062 0cm00542559 71139834 0cm00542582 71140169 71140170 #0cm00542582 0cm00542584 71140175 ocm00542598 69741270
Then, with this second regex S/Ri, it combines two operations, separated by the
|
character :-
It matches, successively, any line with
8
characters only and its EOL chars and adds, before each of them, the nearest contents, downwards, of a line beginning with a#
char -
It matches all the line beginning with a
#
char and its EOL chars as well and delete it during the replacement phase -
The replacement means :
-
If a line of
8
chars exists, rewrite the value which follows the#
( so11
chars ) and, after a space char rewrite the8
chars of the current line -
Else, it deletes the line beginning with a
#
( as nothing follows the colon in the conditional replacement )
-
SEARCH
(?-s)^(.{8}\R)(?=(?:.{8}\R)*#(.+))|#.+\R
REPLACE
(?1$2 $1:)
And here is your expected OUTPUT text :
0cm00542421 70559817 0cm00542424 69948854 0cm00542424 69948855 ocm00542436 71133882 ocm00542442 71139953 ocm00542459 69705562 ocm00542468 71149982 ocm00542470 69787610 ocm00542476 70958115 ocm00542488 71150286 ocm00542488 71150287 ocm00542497 70157118 ocm00542498 71126285 ocm00542502 69801834 ocm00542515 69996642 ocm00542515 69996643 ocm00542515 69996644 ocm00542515 69996645 ocm00542515 69996646 ocm00542515 69996647 ocm00542515 69996648 ocm00542515 69996649 ocm00542515 69996650 ocm00542515 69996651 ocm00542515 69996652 ocm00542515 69996653 ocm00542515 69996654 ocm00542515 69996655 ocm00542515 69996656 ocm00542515 69996657 ocm00542515 69996658 ocm00542515 69996659 0cm00542526 69961542 0cm00542538 69828403 0cm00542548 71140062 0cm00542559 71139834 0cm00542582 71140169 0cm00542582 71140170 0cm00542584 71140175 ocm00542598 69741270
So, in short, the text below :
A V0 V1 V2 V3 ... ... ... Vn
Is first changed as :
A V0 V1 V2 V3 ... ... ... Vn #A
And becomes finally :
A V0 A V1 A V2 A V3 ... ... ... A Vn
I hope that I correctly interpreted your needs !
Best Regards,
guy038
-
-
@guy038 said in How to mass shift and paste (see attached):
(?1$2 $1:)
You’re a lifesaver! Thank you so much!