Multiple text and combine in specifique line order.
-
Hi all!
Im new in notepadd ++.
How can we do this?
text 1
ping 1.1.1.1 repeat 10 sou GIGABITETHERNET0/0/0.12
ping 2.2.2.2 repeat 10 sou GIGABITETHERNET0/0/0.12
ping 3.3.3.3 repeat 10 sou GIGABITETHERNET0/0/0.12text 2
circuit 1 path 1
circuit 2 path 2
circuit 3 path 3text 3
#####################{Enter}aaa ####{Enter}
#####################{Enter}
111
#####################{Enter}bbb ####{Enter}
#####################{Enter}
222
#####################{Enter}ccc ####{Enter}
#####################{Enter}
333Thes final result should be :
#####################{Enter}
circuit 1 path 1 ####{Enter}
#####################{Enter}
ping 1.1.1.1 repeat 10 sou GIGABITETHERNET0/0/0.12
#####################{Enter}circuit 2 path 2 ####{Enter}
#####################{Enter}
ping 2.2.2.2 repeat 10 sou GIGABITETHERNET0/0/0.12
#####################{Enter}circuit 3 path 3 ####{Enter}
#####################{Enter}
ping 3.3.3.3 repeat 10 sou GIGABITETHERNET0/0/0.12Thank!!! :)
-
@AV-Chan said:
How can we do this?
First off, welcome to the “community”.
Your solution can be achieved, fairly simply although it does take a few steps. I had presented a similar solution some time ago. As you will see below the 3 groups of text are preceded by an increasing number followed immediately by a character (a,b or c). In order to achieve this it is easiest if the 3 groups of text are in separate files initially.So for the file containing text 1 have the cursor in the very first position on the first row. Select “Edit”, then “Column editor”. Use text to insert and type the "c " (note a space follows the c) and press OK. You will see every line is preceded by an “c<space>”. Without moving the cursor, repeat the “column editor” function, however this time we are getting an ascending number to start each line, so “number to insert” radio button must be selected first. So the entry is “4” in initial number, increase by is “4” and also tick the “leading zeros” button before pressing the OK button. The result will be similar to the example text below, however you may have more leading zeros. So if 1000 lines in file “text 1” the first line will be "0004c ", second "0008c " etc.
For the file “text 2” the same steps are taken, however the text to insert is "b " (note space after b). Then for the number to insert we have “2” as initial number and “4” as increase by, again with leading zeros ticked.
For file “text 3”, again similar steps with text to insert being "a " (note space after a) and for number have “1” as initial number and “1” as increase by, again with leading zeros.
Once all this completed, combine the 3 files into 1. Then sort the file using Edit", then “Line Operations”, then “Sort lines as integers ascending”. What this achieves is to place the replacement lines directly below the line they are to be inserted into.
Now comes the “regex” part, that “regular expression” to you. So you start with “Search”, then “Replace”. This part needs the selections that I nominate below, otherwise it will NOT work.
Into the “Find what” field type:
(?-s)^(\d+)a.+\R(\1b.+\R)
Into “Replace with” field type:
\2
YouMUST
have “regular expression” selected. Make sure the cursor is again in the very first line, first position. Click on the “Replace All” button. Have a quick check, you should see the first few lines have updated, that will continue throughout the combined file.If happy, then you will again invoke the “Replace” function, this time changing the “b” in the “Find what” field with a “c”, again run the “Replace All” command.
So a bit of background about the “regexes”"
(?-s)
prevents the.
meaning a newline character, even if it is selected in the replace function. It overrides that selection.
^
means start at the first character on a line.
(\d+)a.\R
looks for the number, remembers it as it has()
around it, then looks fora
and then as many characters as necessary to get to the end of the line, followed by the line feed/character return.
(\1b.+\R)
will look for the same number as the previous line had\1
followed by ab
, and again characters to the end of the line followed by the line feed/character return.In the “replace with” field the
\2
means we replace all we looked at with the contenst of the second set of brackets we used on the “Find with” field, hence the(\1b.+\R)
, or as in the second regex(\1c.+\R)
.text 1
04c ping 1.1.1.1 repeat 10 sou GIGABITETHERNET0/0/0.12
08c ping 2.2.2.2 repeat 10 sou GIGABITETHERNET0/0/0.12
12c ping 3.3.3.3 repeat 10 sou GIGABITETHERNET0/0/0.12text 2
02b circuit 1 path 1
06b circuit 2 path 2
10b circuit 3 path 3text 3
01a #####################{Enter}
02a aaa ####{Enter}
03a #####################{Enter}
04a 111
05a #####################{Enter}
06a bbb ####{Enter}
07a #####################{Enter}
08a 222
09a #####################{Enter}
10a ccc ####{Enter}
11a #####################{Enter}
12a 333I hope that helps you. Please do come back to us and let us know if it helps, or if it did not work, what actually happened. We can revisit the problem if we get the necessary examples to explain what went wrong.
Terry
-
@AV-Chan said:
How can we do this?
Sorry, I missed 2 crucial steps in my explanation. Before running the “regexes” make sure the very last line of the combined file has a blank line.
Then once you have completed the work with the “regexes” you need to remove the number/character combo at the start of each line. This is achieved by again using the Replace with function. Into the “find what” field type:
^\d+.\s
and make sure the “replace with” field is empty. Run it (replace all button) and you should remove all line prepended characters.I typed up offline, only to have missed two vital steps, sorry about that.
Terry
-
@AV-Chan said:
How can we do this?
Version 2 of the solution.
For the files containing text 1 and 2, use the step (i mentioned in first post) to prepended characters for file 2. So both these files will have a number (with leading zeros), both followed by ab
character and a space.For the regex to apply (after making sure last line is a blank line).
Find What:(?-s)^(\d+)a.+\R(\1b.+\R)
Replace With:\2
We can do this as the 2 lines we are ‘inserting’ will never be in the same location, thus designating differently as ‘b’ and ‘c’ is not required.
And lastly I’ve also managed to combine to removal of the prepended characters and removing the last line as 1 regex.
Find what:^\d+[ab]\s|\R\z
Replace With: <— nothing in this fieldIf any issues/queries please do post back. Actually, post back if it all works as planned. We ALL like the
warm fuzzy feeling's
we get from a good result.Terry