• Find specific string in file 1 and replace in specific lines in file 2

    2
    0 Votes
    2 Posts
    319 Views
    Terry RT

    @Denis-Sta said in Find specific string in file 1 and replace in specific lines in file 2:

    Does anyone can give me some hints from where to start?

    Well I’d say you are going to have to merge the 2 files if you want regex (regular expression) to do the work. That’s not as bad as it sounds. There have been several discussions in the past on this forum regarding similar needs to yours. I think most have had solutions found using just regexes.

    The alternative would be a scripting language, Python is one amongst many that Notepad++ supports. But the issue here will be to have someone create a program for you in that language or will you need to learn it yourself.

    In broad terms I’d:

    Make the several lines in each file become one for each “record” Sequence up an ascending number at the start of each line, sort of a line number, odds for 1 file, evens for the other. The lines in file 1 may not be required to have an ascending number at the front but I’ve included it for the time being. Have at the front of each line in both files the appropriate sequences of text you will be using to find the lines. Sort the lines (once both files merged) in ascending order. This will “pair” records together. Use a regex to update the record in the line from file 2 from it’s “pair”. Use a regex to remove the lines from file 1 and to also remove the “sort text” at the front of line. Sort the lines again with the “line number” from step 2. This will put them back in “original order”. Pull apart the lines so they look as they did originally, but now with the additional information you wanted added.

    I replied to someone else recently that often a “BIG” problem like yours looks insurmountable. That is until we break it down into little steps, each then becomes fairly simple to code.

    Terry

  • How to insert text at the end of every url (via a macro)?

    7
    0 Votes
    7 Posts
    857 Views
    khk khkK

    Dear Peter,

    this was the information I needed; now the macro works fine.

    Lots of thanks to all who (tried) to help me.

    Kr

    Kurt

  • RegEx text search

    2
    0 Votes
    2 Posts
    151 Views
    No one has replied
  • Unable to Allow regex backward search

    2
    0 Votes
    2 Posts
    200 Views
    EkopalypseE

    @Matthieu-gabrielli

    I don’t think you’re using the regex backwards search.
    At least the screenshot doesn’t show that you do as you have to tick
    the little checkbox next to Find Next button to see the forward and backward search buttons.

    c7923036-3820-4eac-8060-8b291fef7c49-image.png

    But I don’t think it is needed in your case.
    Strange that this basic regex is not working in your case, are you sure
    you haven’t, by accident, added an additional space to find what?
    Or maybe this document is using linux eol instead of windows eol?

  • "Find Previous" custom keyboard shortcut not working in v7.8.9

    5
    0 Votes
    5 Posts
    372 Views
    I

    That fixed it! Thank you so much @Ekopalypse!

  • Settings Preferences issue

    3
    0 Votes
    3 Posts
    233 Views
    Tim MartinT

    @PeterJones
    Holy cow, I am incredibly embarrassed. I have my screen setup with notepad++ in the upper left corner and when I go to preferences, what I pasted into my post was all I was seeing. After I saw your post I did it again and scooted the window over and – well, thanks for helping me find what was there all along…

  • How to insert text at the end of every url?

    3
    0 Votes
    3 Posts
    977 Views
    PeterJonesP

    @Rob-K ,

    I just said:

    FIND = (?i-s)^\h*https?://test.domain\S* REPLACE = $0 new stuff

    The FIND would be better as:

    FIND = (?i-s)^\h*https?://test\.domain\S*

    Quick explanation of the regex:

    the stuff in parentheses set up options to make it case insensitive and to not let . match newline

    ^ means the match starts at the beginning of the line

    \h* allows 0 or more horizontal spaces (tabs and space characters) before the url

    https?:// allows either http or https

    \. escapes the ., so it means a literal domain separator, not the regex wildcard character

    \S* means that there can be 0 or more additional non-space characters after the domain; since the end-of-line sequence counts as space character, it will stop at the end of the line if there’s nothing after the URL

    $0 in the REPLACE means the entire matched text – so everything from beginning of line to just before the first space (or end-of-line).

    new stuff indicates the new text you want to add

    This means that the replacement will still include the original URL, plus the new stuff.

  • Synchonize by line

    2
    0 Votes
    2 Posts
    164 Views
    EkopalypseE

    @Laurent-Cnoname

    Not as far as I know. You could of course turn off the word wrapping
    but you probably have that on to avoid horizontal scrolling, haven’t you?

  • I would like to find lines where there are 2x double spaces

    18
    0 Votes
    18 Posts
    2k Views
    Thomas 2020T

    this is it:
    Schowek02.jpg

  • File text replaced with "NuL", how do i see/recover it?

    6
    0 Votes
    6 Posts
    1k Views
    sgtsixpackS

    I just created a list of files using defraggler and npp showed the same behavior. When I tried to open it in microsoft notepad although it took a lot longer the data was intact. I know its a bit late but if have u tried notepad to read your “important” codes?

  • golang..

    2
    0 Votes
    2 Posts
    179 Views
    EkopalypseE

    @JACKCHEN213

    There is an udl for golang here.

  • 0 Votes
    2 Posts
    201 Views
    EkopalypseE

    @Mark-Tinney-0 said in Python runs differently in NPP Exec Console vs Windows Console.:

    prefix = ’ ’
    body = ‘┌──────────────────────────────────────────────────────────────┐’
    suffix = ’ ’

    print(prefix+body+suffix)

    Is this something you have under your control?
    If so, you could create a unique environment variable and check this from your script.
    Something like this.

    In NppExec execute you do

    NPP_SAVE $(FULL_CURRENT_PATH) set_env CALLED_FROM_NPP_EXEC=1 D:\ProgramData\Python\Python_embed_382_64\python.exe "$(FULL_CURRENT_PATH)" env_unset CALLED_FROM_NPP_EXEC

    and in python script you do

    import os print(f'{"CALLED_FROM_NPP_EXEC" in os.environ = }')
  • 0 Votes
    9 Posts
    3k Views
    mkupperM

    Thank you @Ekopalypse for the explanation of styles vs. indicators. After a few days of using npp with the python script modified indicators I’m quite happy with the results.

  • Using RegEx in Notepad++ to delete all lines contain certain keywords?

    3
    0 Votes
    3 Posts
    617 Views
    Terry RT

    @Terry-R said in Using RegEx in Notepad++ to delete all lines contain certain keywords?:

    if the word cat or fish is part of a larger word it will still be removed

    A slightly revised regex would be
    Find What:^(.+)?(\bcat\b|\bfish\b)(.+)?\R?

    This expects non word characters (boundaries) to exist around the words cat and fish, thus cat-2 is still caught.

    Terry

  • RegEx... Exchange

    7
    0 Votes
    7 Posts
    355 Views
    astrosofistaA

    @Pan-Jan said in RegEx... Exchange:

    I don’t have a \R

    Try \v for vertical whitespace. Perhaps it works in that editor.

  • 0 Votes
    4 Posts
    357 Views
    Batuhan HınçalB

    @PeterJones it worked, you’re a big man with big heart you saved me precious hours of my time

    I wish a lot of people help you in your life, god bless you.

  • Default save as option

    4
    0 Votes
    4 Posts
    1k Views
    EkopalypseE

    @Makwana-Prahlad,

    current versions, like 7.8.9, append an extension to the name if possible.

  • Inserting g code using replace

    5
    0 Votes
    5 Posts
    933 Views
    guy038G

    Hi, @crafty-crafty, @ekopalypse, and All,

    From the @ekopalypse macro solution, here is an similar solution which can be generalized to :

    Any number of lines which are to be replaced, in the limit of 2,048 characters

    Any number of lines which are to be inserted, during the replacement

    But, first, let’s suppose that you simply have a specific line, repeated many times in your file, which must be replaced with a specific block of lines. Assuming that this line is named #Line# :

    Open a new tab ( Ctrl+ N )

    Type in the specific line #Line# line, followed with a line-break

    Select the entire line #Line#, with its line-break

    Open the Find dialog ( CTRL + F )

    Select, if necessary, the Normal search mode

    Leave all the other options unchecked

    Click on the Find Next button ( Of course, no other occurrence is found, but it does not matter ! )

    Close the Find dialog ( Esc )

    Run the option Macro > Start Recording

    Hit the F3 key ( Whatever an occurrence is found, or not, does not matter ! )

    Hit the Ctrl + V shortcut ( The present contents of clipboard do not matter, too ! )

    Run the option Macro > Stop Recording

    Then, run the option Macro > Save Currently Recorded Macro...

    Type in Replace Next Occurrence with Clipboard Contents, in the Name zone

    Preferably, create a shortcut for this macro

    Click on the OK button to valid the dialog

    Create or select the block of lines, in any file, which must replace the #Line# line

    Copy this block of lines in the clipboard ( Ctrl + C )

    Now, open or select your specific file

    If necessary, move to the very beginning of file ( Ctrl + Home )

    Run the option Macro > Run a Macro Multiple Times...

    Select the Replace Next Occurrence with Clipboard Contents macro

    Tick the Run until the end of file option

    Click on the Run button

    Voila ;-))

    Remark :

    After finding all the occurrences of the specific line, a last search operation is carried on, without success. So, the last #Line# line is replaced by two or more consecutive contents of the clipboard. Thus, a last task has to be done :

    Delete the few extra blocks of text that have been wrongly inserted, after the last match !

    As said above, this macro is not specific and can be used to insert any contents of the clipboard, in replacement of any specific text, even split on several lines, as long as the total amount of text is smaller than 2,048 characters ( Max size of the Find what: zone )

    So, now that the macro Replace Next Occurrence with Clipboard Contents has been created, the road map becomes :

    Create and select the text range which is to be replaced

    Open the Find dialog ( CTRL + F )

    Select, if necessary, the Normal search mode

    Leave all the other options unchecked

    Click on the Find Next button ( Whatever an occurrence of the range is found or not does not matter ! )

    Close the Find dialog ( Esc )

    Create and select the text range, in any file, even split on several lines, which will replace the initial range

    Copy this text range in the clipboard ( Ctrl + C )

    Now, open or select the specific file, where the replacements must occur

    If necessary, move to the very beginning of the file ( Ctrl + Home )

    Run the option Macro > Run a Macro Multiple Times...

    Select the Replace Next Occurrence with Clipboard Contents macro

    Tick the Run until the end of file option

    Click on the Run button

    Finally, delete the few extra range of text that have been wrongly inserted, after the last matched range !

    Best Regards

    guy038

  • How to insert text into the second line with RegEx in Notepad ++ ?

    21
    0 Votes
    21 Posts
    5k Views
    Thomas 2020T

    Schowek01.jpg

  • Add the Icon to the toolbar

    32
    0 Votes
    32 Posts
    9k Views
    Thomas 2020T

    Here some even write in Italian.

    The problem is to explain what problem I have with Notepad.
    Even the English don’t always understand each other.
    How I am trying to explain in short sentences
    some write that I am rude or arrogant.

    Today I figured out how to use
    Google translator.
    Dzisiaj wpadłem na pomysł jak używać Google translatora,
    aby tłumaczenie było jak najlepsze.