Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

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

    Help wanted · · · – – – · · ·
    3
    6
    433
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Craig McFarlane
      Craig McFarlane last edited by

      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.

      Alan Kilborn 1 Reply Last reply Reply Quote 0
      • Alan Kilborn
        Alan Kilborn @Craig McFarlane last edited by

        @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).
        Alan Kilborn 1 Reply Last reply Reply Quote 3
        • Alan Kilborn
          Alan Kilborn @Alan Kilborn last edited by

          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.

          1 Reply Last reply Reply Quote 3
          • Craig McFarlane
            Craig McFarlane last edited by

            @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?

            Alan Kilborn 1 Reply Last reply Reply Quote 0
            • Alan Kilborn
              Alan Kilborn @Craig McFarlane last edited by

              @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.

              1 Reply Last reply Reply Quote 1
              • guy038
                guy038 last edited by

                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

                1 Reply Last reply Reply Quote 2
                • First post
                  Last post
                Copyright © 2014 NodeBB Forums | Contributors