Community
    • Login

    Need Macro to recursively change CRLF (windows) to LF (Unix)

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    8 Posts 5 Posters 2.8k Views
    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.
    • Maurizio MorettiM
      Maurizio Moretti
      last edited by

      Hi all,
      I have a large set of XML files (over 200) where I want to change the CRLF (windows standard) to LF (UNIX standard) in every file. then save and close them.
      I tried recording a Macro, but when i launch it nothing happens.

         <Macro name="Change_to_Unix" Ctrl="no" Alt="no" Shift="no" Key="0">
              <Action type="0" message="2025" wParam="0" lParam="0" sParam="" />
              <Action type="0" message="2422" wParam="0" lParam="0" sParam="" />
              <Action type="0" message="2325" wParam="0" lParam="0" sParam="" />
          </Macro> 
      

      Is the above feasible? and if yes, what am missing?

      1 Reply Last reply Reply Quote 0
      • Maurizio MorettiM
        Maurizio Moretti
        last edited by

        That was dumb of me…
        Fixed it myself. Recording the macro using the ddwn menus did the trick

        andrecool-68A 1 Reply Last reply Reply Quote 3
        • andrecool-68A
          andrecool-68 @Maurizio Moretti
          last edited by

          @Maurizio-Moretti The option to find and replace is not suitable?
          You can hush up in general directories or in all open documents.

          Imgur

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

            Hello, @maurizio-moretti and All,

            Maurizio, welcome to the N++ Community ;-))


            If your set of XML files are gathered in a single folder, you may also use a simple regex S/R :

            • Open the Find in files dialog ( Ctrl + Shift + F )

            • SEARCH \R

            • REPLACE \n

            • Choose *.xml as Filters

            • Enter the absolute path of this folder, in the Directory zone

            • Select the Regular expression mode

            • Click on the Replace in Files button

            • Confirm the small Are you sure? dialog

            Et voilà !

            Notes :

            • This regex S/R works, also, even if some of your files contain mixed EOL !

            • If some of these files are already opened in current N++ session, I advice you to close and restart Notepad++, in order to visualize their new EOL status : Unix(LF), in the status bar

            Best Regards,

            guy038

            Sorry, @andrecool-68, we posted, almost, at the same moment ;-))

            1 Reply Last reply Reply Quote 3
            • andrecool-68A
              andrecool-68
              last edited by andrecool-68

              @Maurizio-Moretti
              @guy038
              These are commands from the notepad ++ menu.

              POPUP "EOL Conversion"
              {
              MENUITEM "Windows (CR LF)",  45001
              MENUITEM "Unix (LF)",  45002
              MENUITEM "Macintosh (CR)",  45003
              }
              

              But the macro record does not see them.
              How to use these commands in the macro, and apply them to all open files and directories opened in “Folder as Workspace”

              Alan KilbornA 1 Reply Last reply Reply Quote 2
              • Alan KilbornA
                Alan Kilborn @andrecool-68
                last edited by

                @andrecool-68 said:

                But the macro record does not see them

                You are correct in this. I think there are A LOT of commands that the macro recorder doesn’t see. Pity. Because right when you are in the middle of recording something you really really need to record, you always seem to hit one of these and it destroys the concept.

                At least with this one you can record a regex replacement operation into the macro as a workaround.

                …and apply them to all open files and directories opened in “Folder as Workspace”

                Isn’t going to work…unless you specify the folder in the Replace in Files directory box and tell it to do subfolders as well

                andrecool-68A 1 Reply Last reply Reply Quote 3
                • andrecool-68A
                  andrecool-68 @Alan Kilborn
                  last edited by

                  @Alan-Kilborn
                  I made a macro as suggested @guy038 only added “apply to all open files” … for now this is enough for me

                  1 Reply Last reply Reply Quote 3
                  • dinkumoilD
                    dinkumoil
                    last edited by dinkumoil

                    @Maurizio-Moretti , @andrecool-68

                    Another approach is to use my AutoEolFormat plugin, available via PluginManager (up to Notepad++ v7.5.9) and PluginsAdmin (Notepad++ v7.6 and higher).

                    1. Install the plugin.
                    2. Configure it to automatically set EOL format for XML files to Unix style (LF).
                    3. Open all XML files to convert (EOL format will be converted automatically).
                    4. Click on Save all.

                    To save RAM maybe do not open all XML files at once, open maybe 40 or 50 (depends on the size of the files).

                    1 Reply Last reply Reply Quote 4
                    • First post
                      Last post
                    The Community of users of the Notepad++ text editor.
                    Powered by NodeBB | Contributors