• Login
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.
  • M
    Maurizio Moretti
    last edited by Jun 23, 2019, 10:55 AM

    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
    • M
      Maurizio Moretti
      last edited by Jun 23, 2019, 11:18 AM

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

      A 1 Reply Last reply Jun 23, 2019, 12:06 PM Reply Quote 3
      • A
        andrecool-68 @Maurizio Moretti
        last edited by Jun 23, 2019, 12:06 PM

        @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
        • G
          guy038
          last edited by guy038 Jun 23, 2019, 12:26 PM Jun 23, 2019, 12:20 PM

          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
          • A
            andrecool-68
            last edited by andrecool-68 Jun 24, 2019, 5:15 AM Jun 24, 2019, 5:14 AM

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

            A 1 Reply Last reply Jun 24, 2019, 12:58 PM Reply Quote 2
            • A
              Alan Kilborn @andrecool-68
              last edited by Jun 24, 2019, 12:58 PM

              @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

              A 1 Reply Last reply Jun 24, 2019, 2:04 PM Reply Quote 3
              • A
                andrecool-68 @Alan Kilborn
                last edited by Jun 24, 2019, 2:04 PM

                @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
                • D
                  dinkumoil
                  last edited by dinkumoil Jun 25, 2019, 1:15 PM Jun 25, 2019, 1:13 PM

                  @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
                  2 out of 8
                  • First post
                    2/8
                    Last post
                  The Community of users of the Notepad++ text editor.
                  Powered by NodeBB | Contributors