remove everything from text file and replace with....



  • Hi guys.

    I have about 1000 configuration files that have about four lines of text in them. I am looking for a way to remove everything from the file and replace with

    input_overlay = “/storage/emulated/0/RetroArch/overlays/McFarlane-Systems.cfg”
    input_overlay_enable = “true”

    I have seen from my other post how I can replace text that’s already there and have learned from that. However looking to blank and file and replace with text.

    Thank in advance for any help.



  • @Craig-McFarlane

    Some hints:

    • If you search for (?s).* (in Regular Expression mode) then it will match all content of a file
    • If you need to have multiple lines in your replacement, you have to put all of your data on one “line” in the Replace with box (because that is all it has), and separate each line’s data with \r\n (or \n in the case your files are Linux format).


  • Additional hints:

    When I said:

    …then it will match all content of a file

    This was meant when you are doing a “file level” operation, e.g. Replace in Files, which you definitely implied that you were going to do.

    you have to put all of your data on one “line” in the Replace with box

    The box has a limit of around 2046 characters; just sayin.

    Also, before doing any type of large operation on all of these files, I implore you to create a backup copy of the originals.



  • @Alan-Kilborn said in remove everything from text file and replace with....:

    \r\n

    Thanks mate. last question. What is the file is already blank. There is nothing to find so nothing to replace. Is there a way to still add the data if the file is empty?



  • @Craig-McFarlane

    Notepad++'s file-level Find functions don’t seem to be too friendly when trying to find zero-length files, as far as I can tell.



  • Hello, @craig-mcfarlane, @alan-kilborn and All,

    I just gave it a try :

    • First, in a Windows console DOS, I ran the command Copy nul Test.txt

    • I opened the file Test.txt from within Notepad++

    • Unfortunately, the regex S/R below does not work, even if the search, only, does detect a zero length match !

      • SEARCH \A^

      • REPLACE Blah blah

    Best Regards,

    guy038


Log in to reply