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



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



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



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

    Imgur



  • 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 ;-))



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



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



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



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


Log in to reply