I am struggling hard on this one.
I need to parse a portion of rtf1 document to rtf2 document. Here is the basic approach:
1) Open rtf1 in notepad and find the unique start point(line) and end point(line).
2) Copy portion from point start point to end point and insert it in rtf2 document.
I know how to insert the portion in rtf2 document but couldn't figure out how to extract the portion. The portion that needs to be copied is lengthy so I have to find a way to input start point and end point so I can use those two reference points to extract anything that falls in between.
Thank you in advance for your valuable input.
Zora
Find startPoint.*?endPoint using Regular expression -search mode with . matches newline enabled. Then copy selected text to clipoard.
.*? basically means "match any character until end point is found".
Remember to escape any special characters when defining the start- and endpoints.
|.......before.......|....portion-to-copy....|.....after..........|
If I need to perform such a task, I use simple method (in Notepad, Notepad++) - you can try it, too:
With text cursor at start point, you can press Ctrl+Shift+Home and then Delete. This deletes all content before your portion. (Do not save the file.)
With text cursor at end point, you can press Ctrl+Shift+End and then Delete. This deletes all content after your portion. (Do not save the file.)
Now you have only your portion. Press Ctrl+A (select all), then Ctrl+C to copy it into the clipboard. In SAS: Press Ctrl+Home, then press Ctrl+Shift+End. Then press Ctrl+C.
Paste your portion where you need.
Close your original document (used in steps 1-3) without saving.
Related
A colleague has inserted duplicates for ~1200 entries into our database. They have sent me a text file containing both the originals and copies in alternating lines of CSV text. I've opened that up in VS Code with the goal of converting the lines representing duplicates into DELETE statements targeting our database. No line is truly identical to another—every two is a pair in which the data is the same other than the row ID.
I have found Stack Overflow entries for removing every other line when the line is empty, or when every other line is an exact copy of the previous line. I have not found an entry this scenario in which the lines have a difference. E.g. I tried using (.*)\n\1 w/ $1\n from another SO entry, which seems to target truly duplicate lines.
So how do I use VS Code to delete every other line regardless of content?
You can achieve this using Replace-All UI in regex mode.
Press command-F or control-F
Expand the arrow on the left of the Find display
Press the ".*" so that it's highlighted
Enter this for Find (top text field in the Find UI): (.*\n)(.*)\n (basically select two lines but save the contents of the first line in the regex system)
Enter this for Replace (following text field in the find UI): $1 (take the line saved from the Find regex and re-insert it)
Hit the Replace All button
Here's a similar SO question
In sublime 3.2.2 I need to copy and paste multiple selection to end of each line. What I did was Edit>replace, enter find term using regex, press alt+enter, press Ctrl +c, press key end, press Ctrl+v. Now what happens is like below,
1.a (a) here
2. a (b) here
regex find is \(\w\)
I get like,
1.a (a) here
(a)
(b)
2. a (b) here
(a)
(b)
Insted of
1.a (a) here(a)
2. a (b) here(b)
I tried for small number of lines it worked, But when having five thousands like it give results as not desired. Same problem in my visual studio code also.
You can do this with a regex search and replace in Sublime, assuming that you'll only have at most one match per line. Select Find → Replace…, make sure the Regex (*) button is selected, and enter (per your example) (\(\w\))(.*) in the Search field. This creates two capture groups - the desired letter surrounded by parens, and the rest of the line after the close paren.
In the Replace field, put \1\2\1. Hit Replace All (CtrlAltEnter) and you should be good to go.
Alternatively, you can try this: Use your original regex and Find All, hit CtrlC to copy, then End. Then, before you paste, hit CtrlShiftL) to split the selection into lines. Now you can hit CtrlV and it should paste how you want.
Dvelving straight into the problem; all I'm trying to do here is to duplicate a line and add a bracket at the end using Regular Expressions and automate the process through the Replace With dialog in Notepad ++.
My issue visualized:
In the representation underneath, I have a bunch of instances of "["Mesh"]" that all have different path values assigned to it. All I want to do is duplicate it the path entry and add bracket at the end before the comma in the duplicated one.
What I have right now:
...
["Mesh"] = Platform(
"models/ships/japan/Zuikaku.mmod",
...
What I'm trying to achieve:
...
["Mesh"] = Platform(
"models/ships/japan/Zuikaku.mmod",
"models/ships/japan/Zuikaku.mmod"),
...
Without getting too specific, since there are ~500 of these instances across the file I'm modifying, I do not want to go through each one while simply clicking CTRL + D to duplicate each line and add the bracket as that would take literal ages to do.
I have some limited experience with Regular Expressions from previous uses, but very limited. I know I can select the entire line in the Search dialog using ".*" but that's as far as I've gotten.
Thank you in advance for your time!
You should be able to use this regex (disable . matches newline). I am using (\R+) to capture end-of-line characters (and reproduce them in the output) so that it will work on systems that use other than just newline to end lines.
(\["Mesh"\]\s*=\s*.*(\R+))(.*),$
Replace with
$1$3,$2$3\),
For the input of
...
["Mesh"] = Platform(
"models/ships/japan/Zuikaku.mmod",
...
This gives
...
["Mesh"] = Platform(
"models/ships/japan/Zuikaku.mmod",
"models/ships/japan/Zuikaku.mmod"),
...
I often need to translate a document in MS Word and I do it paragraph by paragraph, the translation text follows each individual paragraph of the original text. What I need is a keyboard shortcut to move the insertion point to the blank space after the following paragraph I need to translate, i.e to move the cursor from the end of the red colored text in the picture to the blank space after the following paragraph ending with "..and call it a day"
Ctrl+Down Arrow shortcut in Word places the insertion point at the beginning of every following paragraph, while I need it placed at the beginning of the blank line above it so I can immediately start typing.
I am looking for a Word shortcut key, regex expression or an autohotkey script that could perform this task, it would come handy to me in doing translation in MS Word.
Thank you for the help!
On MCL's suggestion I've created a simple Autohotkey script to solve the problem, combining Word keyboard shortcuts into one. I also added a code from another script which sets dark red color of the text which is being typed into the original document to make the contrast with the default text color of the original. This is a convenient option for translators which also allows saving only the translated text by using Find function in Word, and removes the need for any further editing of the translated document. Here's the script:
#IfWinActive ahk_class OpusApp
^2::
Send ^{Down}
Send ^{Down}
Send ^{Left}
Send {Enter}
{
oWord := ComObjActive("Word.Application") ; MS Word object
wdColorDarkRed = 128
oWord.Selection.Font.Color := wdColorDarkRed
}
return
I have a file containing (hundreds) of blocks of numbers like below;
This one is fine (16x20, correct number of rows and columns)
11111111111111111110
16666616666666661110
16111616111111162610
16111646111663132610
16162616261623132610
16162313261623132610
16162313261623132610
16162313261623132610
16162313261623132610
16162313261623132610
16162313261623132610
16162313261626132610
16166313661116632610
16111111111116132610
16666666666666136610
11111111111111111110
This one needs to be padded with trailing zeroes so it is (16x20)
111111111111111111
166616666666663661
166611111111111661
166666366663661661
113161111111161611
1316166666616161
1616162262616161
11616166112616161
16616166116616161
16616162262616161
16616166266616161
16616111161116161
1661666666666616111
1661666166163366661
1641666166166613661
1111111111111111111
I would like to pad them with zeroes so they are all like the first example. I'm aware of the regular expressions feature in notepad++ but am struggling to get it to work. I appreciate any help given.
You could do it via a macro.
First append a large number of zeroes to the end of each line using a macro.
Caret on the first entry
click record macro
press end
type out 20 zeroes
press down arrow
click stop recording
play the macro until all lines look like this
11111111111111111100000000000000000000000000000000000000000000
16661666666666366100000000000000000000000000000000000000000000
16661111111111166100000000000000000000000000000000000000000000
16666636666366166100000000000000000000000000000000000000000000
11316111111116161100000000000000000000000000000000000000000000
131616666661616100000000000000000000000000000000000000000000
161616226261616100000000000000000000000000000000000000000000
1161616611261616100000000000000000000000000000000000000000000
1661616611661616100000000000000000000000000000000000000000000
1661616226261616100000000000000000000000000000000000000000000
1661616626661616100000000000000000000000000000000000000000000
1661611116111616100000000000000000000000000000000000000000000
166166666666661611100000000000000000000000000000000000000000000
166166616616336666100000000000000000000000000000000000000000000
164166616616661366100000000000000000000000000000000000000000000
111111111111111111100000000000000000000000000000000000000000000
Then...
Caret on first line
click record
press home key
press the right arrow key 20 times
hold shift and press end key
press delete key
press down arrow
click stop recording
play the macro until all lines are processed
You could save the entire process as a single macro so its just a single click in the future.
I can give you a macro solution
go to the beginning of your text
select Macro/Start Recording
press end, press 0 16 times then press Home and down arrow key
select Macro/End Recording
You now have a macro to add sixteen zeros to the end of all lines.
Playback this macro on all lines.
You now have appended zeroes to all lines.
Pressing Alt key and using mouse select the required block(columns) of text you want and paste it into another empty notepad tab
help on column mode editing is there inside notepad ? / help contents menu
Good luck
You can use the plugin ConyEdit to do this.
With ConyEdit running in the background, follow these steps:
use the command line cc.aal 00000000000000000000 to append after lines with twenty zero character.
use the command line cc.gc 1/\d{20}/ to get the first column of regex match.
Looking to do this manualy and not progomaticly ?
Open Findreplace
Copy from the last to rhe first WITHOUT NUMBERS on a line so...
in this example
111111111111111111 <---from here
to here ---> 166616666666663661
166611111111111661
paste that into the fine ( yes your effecticly copying the return wich some applications allow you to manualy input others wont )
then in the replace box, type '0' then your return
Hit that magic replace all :D
This will then add a 0 every time it hits a new line, then add a new... new line....
edit : quickly reviewing another method a second to recover for alternate options :P give me 10
edit 2:
Ah ok somthing like this will work :P just tested it.
use [0-9] in the find replace. so if im looking for 123123123123 ( wich is 12 long ) and i need to buff i up to 20,
Your FIND must be in ()
so..
the find would be
([0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9] )
and the replace is referd to as \1 no the regex, this was my mistake
\100000000
tested and confirmed !dont forget YOU NEED MATCH ALL on, WRAP off!
And so on for your other numbers, Not sure if you can loop this with macros nd stuff :P but hope it helps more than you have now
two good resources.
http://blog.creativeitp.com/posts-and-articles/editors/understanding-regex-with-notepad/comment-page-1/
http://regexpal.com/
base on OP's comment: you could try an editor called vim/gvim
open your file in vim, then type:
:%s/.*/\=printf("%-20s",getline("."))/|%s/ *$/\=substitute(submatch(0)," ","0","g")/
don't forget pressing <Enter> after the above typing.
then you will see the text has been changed into what you want.
of course vim macro can work as well, however, I feel command better... :)