How to get total number of lines for multiple files?

How to get total number of lines for multiple files?

7
NewbieNewbie
7

    Mar 27, 2019#1

    Hi,

    Can UltraEdit be used to get total number of lines for multiple files? This is very useful to get statistic info about a project, such as Visual C++ project.

    Thanks.

    6,681583
    Grand MasterGrand Master
    6,681583

      Mar 28, 2019#2

      Run a Perl regular expression Find in Files searching for \r?\n and the find in files output contains for each file how many line endings are found in this file and at bottom the total number of found DOS/Windows or UNIX line terminations in all files. The result is not accurate if there are files with no line termination on last line in file.

      A Perl regular expression Find in Files searching for $ would be a count of all line terminations + 1 for each end of file. So this result is also not really accurate.

      A Perl regular expression Find in Files searching for \r?\n|(?<![\r\n])\z would find and count all DOS/UNIX line endings and end of file if the file does not end with DOS/UNIX line termination. So this find in files result would be really accurate if a string at end of file with no line termination should be counted as line.

      It would be also possible to use a regular expression Find in Files to get only non-blank and non-empty lines in find in file results.
      Best regards from an UC/UE/UES for Windows user from Austria

      7
      NewbieNewbie
      7

        Mar 28, 2019#3

        Hi Mofi,

        Thank you very much. Is it possible to save a search pattern, including all the parameters? Currently I can only save a search by clicking "Add to Favorite". But this will not be able to name the search, which will make me forget what the search pattern is for after some time.

        Also I find when I save a search to Favorite, only the search pattern is saved, the other search parameters, such as the file name, whether to use regular expression, etc. are not saved together. How to save all the search parameters together so that I can invoke it in the future?

        6,681583
        Grand MasterGrand Master
        6,681583

          Mar 28, 2019#4

          A favorite title can be set for each saved search/replace favorite. In Find and Replace window a click on button with star symbol and click next on opened context menu on Edit favorites. Select the saved favorite search/replace string and enter below Favorite title the wanted title string listed finally in submenu Favorites of context menu opened on clicking on button with star symbol.

          But I honestly use the search/replace string favorites only as templates for often needed expressions always adapted after selection to what is currently needed because all the find/replace parameters are not saved with the search/replace string favorites.

          I recommend to record a find/replace often needed with same parameters into a macro. Let's assume you are using already an UltraEdit version with ribbon interface and the ribbon mode is also used by you and not toolbar/menu mode with contemporary or traditional menus.
          1. On (last) ribbon tab Advanced click in fourth ribbon group Macro on down arrow right to item Record and click in popup menu on Define and record. The Macro Definition dialog opens.
          2. Enter as macro name for example Count lines. Uncheck the macro property Show cancel dialog for this macro. The second property does not matter for this macro running just one Find in Files.
          3. You could also define a hotkey or a chord (multi-key hotkey) to later run this macro by key. Then click on button OK.
          4. Run now Find in Files with the appropriate parameters recorded by UltraEdit into the macro.
          5. On (last) ribbon tab Advanced click in fourth ribbon group Macro on item Stop to stop macro recording.
          6. Click next on down arrow right to item Configure and click in pop-up menu on Save all macros. The Save Macro dialog opens.
          7. It is up to you where the macro file is stored. It can be any directory on which you have read/write access. I recommend using directory %APPDATA%\IDMComp\UltraEdit (copy and paste this string into file name field and hit enter to open this directory) into a new subdirectory Macros created by clicking on symbol button Create New Folder or right clicking into the list of folders and files and clicking in context menu in submenu New on menu item Folder. Navigate into new folder Macros.
          8. Enter as name for the macro file whatever you want. I suggest as macro file name AutoLoaded.
          9. On (last) ribbon tab Advanced click in fourth ribbon group Macro once again on down arrow right to item Configure and click in pop-up menu on Set macro for auto-load. The Save Macro Auto Load on Startup dialog opens.
          10. Browse to just saved macro file if this is necessary because of just saved macro file is not automatically selected as macro filename. Click on button OK.
          Now the macro file %APPDATA%\IDMComp\UltraEdit\Macros\AutoLoaded.mac just saved and configured is automatically loaded by UltraEdit on startup. This macro file can contain multiple macros. So you can record or write from scratch more macros at any time and save them all into this macro file loaded on startup of UltraEdit.

          There are multiple methods to run a macro:
          1. The macro can be executed by pressing hotkey/chord on having defined one.
          2. It is also possible to click on (last) ribbon tab Advanced in fourth ribbon group Macro on down arrow right to Play macro in pop-up menu on Play any multiple times, select macro Count lines and execute it.
          3. There is on ribbon tab Layout in second ribbon group Views the check box item Macro list opening the Macro List view listing all macros in currently loaded macro file AutoLoaded.mac on which the macro Count lines can be executed with a double click on it. The Macro List view can be configured to be docked on any side of UltraEdit main application window with auto-hide (pin symbol) turned on to have this list always available with moving mouse pointer over its tab without the need to open in first via ribbon tab Layout.
          4. And depending on used version of UltraEdit the macro Count lines could be also added to a custom ribbon tab or to a toolbar on using toolbar/menu mode for quick execution by mouse.
          Last but not least it would be also possible to code this simple Perl regular expression Find in Files as UltraEdit script which is added to the Script List for quick execution by hotkey/chord, from Script List or a custom ribbon tab or a customized toolbar with the pointing device. A scripting solution could do more than just running the Find in Files as it could process the results written to output window or new file and reformat the results using regular expressions to get finally in output window or in a new file or in clipboard just the data you want in format you would like.

          Of course the same is possible with a macro with the exception that a macro cannot access the output window content. So the Find in Files must be executed with results written to an edit window processed further with the macro with regular expression replaces to wanted data format kept finally in new file or copied to clipboard and closing new file without saving it.

          Conclusion: Getting a line statistic exactly as you want it is possible with writing an UltraEdit script or recording/writing an UltraEdit macro which can be configured for easy execution by hotkey/chord or using pointing device at any time or even automated using a batch file which calls UltraEdit with the parameters to run the macro or script producing the statistic data file.
          Best regards from an UC/UE/UES for Windows user from Austria

          7
          NewbieNewbie
          7

            Mar 29, 2019#5

            Thank you very much