Multiple Replace in Files from list containing also replace properties information

Multiple Replace in Files from list containing also replace properties information

62
Advanced UserAdvanced User
62

    Oct 07, 2017#1

    I have a task for multiple Replace in Files from a find/replace list being attached as find_replace_list.txt.

    There are two strings per line in find_replace_list.txt. First string is the string to find and second string is the replace string. The two strings are separated by two tab characters and the search environment is defined between the tabs.

    Here is the search environment list with as placeholder for the horizontal tab character:
    • ≫≫ ... the string between the tabs is empty:
      perlReOn; regExp=true; matchCase=false; matchWord=false; useEncoding=true; encoding=65001;
    • i ... the string between the tabs is "i":
      perlReOn; regExp=true; matchCase=true; matchWord=false; useEncoding=true; encoding=65001;
    • u ... the string between the tabs is "u":
      ueReOn; regExp=true; matchCase=false; matchWord=false; useEncoding=true; encoding=65001;
    • ui|iu .. the string between the tabs is "ui" or "iu":
      ueReOn; regExp=true; matchCase=true; matchWord=false; useEncoding=true; encoding=65001;
    • r ... the string between the tabs is "r":
      regExp=false; matchCase=false; matchWord=false; useEncoding=true; encoding=65001;
    • ri ... the string between the tabs is "ri":
      regExp=false; matchCase=true; matchWord=false; useEncoding=true; encoding=65001;
    I want a script according to following requirements:
    1. Ask to open find_replace_list.txt. The prompt to open the file is not mandatory. It would be okay to open the file already before running the script.
    2. Ask for file path and file extension.
    3. Find search environment between tabs in opened file find_replace_list.txt.
    4. For each line in list file: The date left to the tabbed data is the search string which should be replaced with the string after the tabbed data in all files.
    Thanks
    replace_in_files.zip (193.3 KiB)   78
    ZIP archive contains two input files, the expected output for both input files and the list file.

    6,681583
    Grand MasterGrand Master
    6,681583

      Oct 08, 2017#2

      Here is the script which I wrote in two hours. Please read the comments for details.

      The modified input files after script execution are not identical to the attached output files, but that is most likely not the fault of the script.

      I do not really understand why i means do not ignore case, but that is your definition.

      Code: Select all

      // These 3 variables can be predefined to avoid user prompts on script execution.
      var sListFile = "";      // "C:\\Temp\\Test\\find_replace_list.txt";
      var sDirectory = "";     // "C:\\Temp\\Test\\input\\";
      var sFileExtension = ""; // "*.htm";
      
      // The script code below works only for a list file with DOS/Windows line endings.
      
      var asListFileData = null;
      var nReplaceCount = 0;
      var bOldVersion = (typeof(UltraEdit.activeDocumentIdx) == "undefined") ? true : false;
      
      if (UltraEdit.document.length > 0)  // Is any file opened?
      {
         // Define environment for this script.
         UltraEdit.insertMode();
         if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
         else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
      
         // Get caret position in active file.
         var nLine = UltraEdit.activeDocument.currentLineNum;
         var nColumn = UltraEdit.activeDocument.currentColumnNum;
         if (bOldVersion) nColumn++;
      
         // Move caret to top of the active file.
         UltraEdit.activeDocument.top();
      
         UltraEdit.perlReOn();
         UltraEdit.activeDocument.findReplace.mode = 0;
         UltraEdit.activeDocument.findReplace.matchCase = true;
         UltraEdit.activeDocument.findReplace.matchWord = false;
         UltraEdit.activeDocument.findReplace.regExp = true;
         UltraEdit.activeDocument.findReplace.searchDown = true;
         if (typeof(UltraEdit.activeDocument.findReplace.searchInColumn) == "boolean")
         {
            UltraEdit.activeDocument.findReplace.searchInColumn = false;
         }
      
         // Does the active file contain at least 3 lines in required format for list file?
         if(UltraEdit.activeDocument.findReplace.find("^(?:.+\\t(?:i|iu|r|ri|u|ui)?\\t.*\\r\\n){3}"))
         {
            // Get the lines in active file into a string array.
            UltraEdit.activeDocument.selectAll();
            asListFileData = UltraEdit.activeDocument.selection.split("\r\n");
         }
      
         // Restore initial caret position in active file.
         UltraEdit.activeDocument.gotoLine(nLine,nColumn);
      }
      
      
      // Are the list file data not loaded already from active file?
      if (asListFileData == null)
      {
         // Is a list file name not predefined in script file, let
         // user of script open any file and hope it is the list file.
         if (!sListFile.length)
         {
            var nDocCount = UltraEdit.document.length;
            UltraEdit.open("");
      
            // Has the user opened an additional file at all?
            if (UltraEdit.document.length > nDocCount)
            {
               // Get the lines in active file into a string array.
               UltraEdit.activeDocument.selectAll();
               if (UltraEdit.activeDocument.isSel())
               {
                  asListFileData = UltraEdit.activeDocument.selection.split("\r\n");
               }
               // Close the opened list file no longer needed.
               UltraEdit.closeFile(UltraEdit.activeDocument.path,2);
            }
         }
         else  // The name of the list file with full path is predefined in script.
         {
            var nDocCount = UltraEdit.document.length;
            var sFileNameWithPath = sListFile.toLowerCase();
      
            for (var nDocIndex = 0; nDocIndex < nDocCount; nDocIndex++)
            {
               // Is the list file opened already in UltraEdit?
               if (UltraEdit.document[nDocIndex].path.toLowerCase() == sFileNameWithPath)
               {
                  // Get caret position in opened list file.
                  var nLine = UltraEdit.document[nDocIndex].currentLineNum;
                  var nColumn = UltraEdit.document[nDocIndex].currentColumnNum;
                  if (bOldVersion) nColumn++;
      
                  // Get the lines in opened list file into a string array.
                  UltraEdit.document[nDocIndex].selectAll();
                  if (UltraEdit.document[nDocIndex].isSel())
                  {
                     asListFileData = UltraEdit.document[nDocIndex].selection.split("\r\n");
                  }
                  UltraEdit.document[nDocIndex].gotoLine(nLine,nColumn);
                  break;
               }
            }
      
            // Is the list file not opened already?
            if (nDocIndex == nDocCount)
            {
               UltraEdit.open(sListFile);
               // Could the file be opened successfully?
               if (UltraEdit.document.length > nDocIndex)
               {
                  // Get the lines in active file into a string array.
                  UltraEdit.activeDocument.selectAll();
                  if (UltraEdit.activeDocument.isSel())
                  {
                     asListFileData = UltraEdit.activeDocument.selection.split("\r\n");
                  }
                  UltraEdit.closeFile(UltraEdit.activeDocument.path,2);
               }
            }
         }
      }
      
      // Are the list file data loaded from active, predefined or specified list file?
      if (asListFileData != null)
      {
         var bCreatedNewFile = false;
      
         // Is a directory path not predefined in script file, ask user
         // of the script for the directory path of the files to modify.
         while (!sDirectory.length)
         {
            if (UltraEdit.document.length < 1)
            {
               UltraEdit.newFile();
               bCreatedNewFile = true;
            }
            sDirectory = UltraEdit.getString("Enter directory path of files to modify:",1);
         }
         // Make sure the directory path ends with a backslash.
         if (sDirectory[sDirectory.length-1] != '\\') sDirectory += '\\';
      
         // Is the file name pattern not predefined in script file, ask
         // user of the script for the file extension/file name pattern.
         while (!sFileExtension.length)
         {
            if (UltraEdit.document.length < 1)
            {
               UltraEdit.newFile();
               bCreatedNewFile = true;
            }
            sFileExtension = UltraEdit.getString("Enter file name pattern (extension) like *.htm:",1);
         }
      
         // Define the replace in files options never modified.
         UltraEdit.frInFiles.filesToSearch = 0;
         UltraEdit.frInFiles.searchSubs = false;
         UltraEdit.frInFiles.directoryStart = sDirectory;
         UltraEdit.frInFiles.searchInFilesTypes = sFileExtension;
         UltraEdit.frInFiles.openMatchingFiles = false;
         UltraEdit.frInFiles.ignoreHiddenSubs = true;
         UltraEdit.frInFiles.logChanges = true;
         UltraEdit.frInFiles.matchWord = false;
         UltraEdit.frInFiles.preserveCase = false;
         UltraEdit.frInFiles.useEncoding = true;
         UltraEdit.frInFiles.encoding = 65001;
      
         for (var nLine = 0; nLine < asListFileData.length; nLine++)
         {
            // Is the active line in array empty, skip the line.
            if (!asListFileData[nLine].length) continue;
            // Split the line up into data strings
            var asData = asListFileData[nLine].split('\t');
            // Skip the line on less than 2 tab characters.
            if (asData.length < 3) continue;
            // Skip the line on search string is an empty string.
            if (!asData[0].length) continue;
      
            // Determine the variable replace in files options for next execution.
            var bApplyWorkaround = true;
            var sOptions = asData[1].toLowerCase();
            if (sOptions == "i")
            {
               UltraEdit.frInFiles.regExp = true;
               UltraEdit.frInFiles.matchCase = true;
               UltraEdit.perlReOn();
               bApplyWorkaround = false;
            }
            else if ((sOptions == "iu") || (sOptions == "ui"))
            {
               UltraEdit.frInFiles.regExp = true;
               UltraEdit.frInFiles.matchCase = true;
               UltraEdit.ueReOn();
            }
            else if (sOptions == "u")
            {
               UltraEdit.frInFiles.regExp = true;
               UltraEdit.frInFiles.matchCase = false;
               UltraEdit.ueReOn();
            }
            else if (sOptions == "r")
            {
               UltraEdit.frInFiles.regExp = false;
               UltraEdit.frInFiles.matchCase = false;
               UltraEdit.ueReOn();
            }
            else if (sOptions == "ri")
            {
               UltraEdit.frInFiles.regExp = false;
               UltraEdit.frInFiles.matchCase = true;
               UltraEdit.ueReOn();
            }
            else
            {
               UltraEdit.frInFiles.regExp = true;
               UltraEdit.frInFiles.matchCase = false;
               UltraEdit.perlReOn();
               bApplyWorkaround = false;
            }
      
            // Output find and replace string in output window.
            UltraEdit.outputWindow.write('Find: "' + asData[0] + '" Replace: "' + asData[2] + '"');
      
            // Workaround for a bug in older versions of UE and UES which do
            // not correct interpret ^p, ^r, ^n, ^t and ^b in replace string
            // of a replace in files executed from within a script. In search
            // string those special escape sequences are interpreted as expected.
            if (bApplyWorkaround)
            {
               // Replace all ^p by carriage return + line-feed.
               var sReplace = asData[2].replace(/\^p/g,"\r\n");
               sReplace = sReplace.replace(/\^r/g,"\r");  // carriage return
               sReplace = sReplace.replace(/\^n/g,"\n");  // line-feed
               sReplace = sReplace.replace(/\^t/g,"\t");  // horizontal tab
               sReplace = sReplace.replace(/\^b/g,"\f");  // form-feed
               asData[2] = sReplace;
            }
      
            // By default every Replace in Files is executed only once.
            var nLoopCount = 1;
            // Are there more than three tab separated values?
            if (asData.length > 3)
            {
               // Consists the fourth value only of digits?
               if (asData[3].search(/^\d+$/) == 0)
               {
                  // The fourth value is a loop count value to run this
                  // Replace in Files multiple times on the files.
                  nLoopCount = parseInt(asData[3],10);
               }
            }
      
            while (nLoopCount)   // Run Replace in Files one or more times.
            {
               // Run the replace in files without evaluation of results.
               UltraEdit.frInFiles.replace(asData[0],asData[2]);
               nReplaceCount++;
               nLoopCount--;
            }
         }
      
         // Close the new file just opened to be able to prompt user for directory
         // path and file extension loaded into variables in older versions of UE.
         if (bCreatedNewFile)
         {
            UltraEdit.closeFile(UltraEdit.activeDocument.path,2);
         }
      }
      
      // Open the output window if any replace in files was executed at all.
      if (nReplaceCount) UltraEdit.outputWindow.showWindow(true);
      
      // Show a small summary output with number of replace in files executed.
      var sPluralS = (nReplaceCount != 1) ? "s" : "";
      UltraEdit.messageBox("Executed " + nReplaceCount + " replace" + sPluralS + " in files.");
      
      Update on 2018-01-10: Added code to interpret a fourth tab separated value as loop count value.
      Best regards from an UC/UE/UES for Windows user from Austria

      62
      Advanced UserAdvanced User
      62

        Oct 08, 2017#3

        Thanks Mofi, for giving me your valuable time again. Your script is awesome for all times.

        There are small updates required for the script:

        Show a small summary output with number of replace in files executed, also show a summary of which strings are not found in files.

        Some find strings are not working
        :
        • <table*">»ui»<table>^p<tbody>
        • </table>»ui»</tbody>^p</table>
        • <!DOCTYPE[\s\S]+?<body>»r»<?xml version="1.0" encoding="UTF-8"?>\r\n<!DOCTYPE html>\r\n<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="nl" lang="nl">\r\n<head>\r\n<title>####</title>\r\n<link href="css/spi.css" type="text/css" rel="stylesheet"/>\r\n</head>\r\n<body>\r\n<section id="@@" epub:type="chapter">
        Please can the script be updated so that these find and replace strings works properly too.
        Should be no change in find_replace_list.txt file.

        Thanks

        6,681583
        Grand MasterGrand Master
        6,681583

          Oct 10, 2017#4

          I added two code and two comment lines to the script above to output find and replace string to output window and open the output window when at least one replace in files was executed. That output works in UE v22.20.0.49 and UE v24.20.0.35 as expected.

          I have not yet looked on why the three replaces you have posted do not work as expected. In UE v24.20.0.35 the first two replaces in files inserting the tags <tbody> and </tbody> also work while not working in UE v22.20.0.49.
          Best regards from an UC/UE/UES for Windows user from Austria

          62
          Advanced UserAdvanced User
          62

            Oct 10, 2017#5

            Hi Mofi

            Thanks for the reply

            Currently I am using UEStudio v11.00.0.1011 and I have faced some of issues following:
            1. UltraEdit regex pattern "^p" is not working on the replaced string. I can't understand why it's not working properly.
            2. Actually my requirement is to enlisted the summary of find replaces which are not execute in the files. But in your script, the output is executed replaces in files.
            3. I would like to create backup at the same directory with ".backup" extension and same file name before execute the replaces for further assistance.
            It will be my pleasure if you can solve this issues

            Thanking you

            6,681583
            Grand MasterGrand Master
            6,681583

              Oct 11, 2017#6

              I updated the script code once more to fix the issue with non regular expression and UltraEdit regular expression replace strings containing ^p, ^r, ^n, ^t or ^b not correct interpreted by older versions of UE and UES in a replace in files executed from within a script by applying a workaround for this issue.

              This workaround can be easily disabled for newer versions of UE/UES with replacing true by false in the line with var bApplyWorkaround = true;

              And there are two mistakes in file find_replace_list.txt:
              1. The replace with search string <!DOCTYPE[\s\S]+?<body> is a Perl regular expression replace. For that reason option r is wrong. The option should be an empty string, i.e. r must be removed from this line.
              2. The replace with search string </body>\r\n</html> is also a Perl regular expression replace. ri must be removed from this line.
              With modification of script and find_replace_list.txt the input files are modified exactly to the output files.

              Please code the other requirements by yourself. I'm not paid for making your job. You can get the text in output window via clipboard and run a regular expression replace to remove the replaces which found and replaced strings.
              Best regards from an UC/UE/UES for Windows user from Austria

              62
              Advanced UserAdvanced User
              62

                Oct 12, 2017#7

                Hi Mofi

                I am very much thankful to you for your kind cooperation.

                I was trying to update the script of by myself.

                I added the two additional requirements to the script by myself:
                • To create backup at the same directory with ".backup" extension and same file name before execute the replaces.
                • To enlisted the summary of find replaces which are not execute in the files.
                Here is the updated script:

                Code: Select all

                // These 3 variables can be predefined to avoid user prompts on script execution.
                var sListFile = "";      // "C:\\Temp\\Test\\find_replace_list.txt";
                var sDirectory = "";     // "C:\\Temp\\Test\\input\\";
                var sFileExtension = ""; // "*.htm";
                
                // The script code below works only for a list file with DOS/Windows line endings.
                
                var asListFileData = null;
                var nReplaceCount = 0;
                var bOldVersion = (typeof(UltraEdit.activeDocumentIdx) == "undefined") ? true : false;
                
                if (UltraEdit.document.length > 0)  // Is any file opened?
                {
                   // Define environment for this script.
                   UltraEdit.insertMode();
                   if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
                   else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
                
                   // Get caret position in active file.
                   var nLine = UltraEdit.activeDocument.currentLineNum;
                   var nColumn = UltraEdit.activeDocument.currentColumnNum;
                   if (bOldVersion) nColumn++;
                
                   // Move caret to top of the active file.
                   UltraEdit.activeDocument.top();
                
                   UltraEdit.perlReOn();
                   UltraEdit.activeDocument.findReplace.mode = 0;
                   UltraEdit.activeDocument.findReplace.matchCase = true;
                   UltraEdit.activeDocument.findReplace.matchWord = false;
                   UltraEdit.activeDocument.findReplace.regExp = true;
                   UltraEdit.activeDocument.findReplace.searchDown = true;
                   if (typeof(UltraEdit.activeDocument.findReplace.searchInColumn) == "boolean")
                   {
                      UltraEdit.activeDocument.findReplace.searchInColumn = false;
                   }
                
                   // Does the active file contain at least 3 lines in required format for list file?
                   if(UltraEdit.activeDocument.findReplace.find("^(?:.+\\t(?:i|iu|r|ri|u|ui)?\\t.*\\r\\n){3}"))
                   {
                      // Get the lines in active file into a string array.
                      UltraEdit.activeDocument.selectAll();
                      asListFileData = UltraEdit.activeDocument.selection.split("\r\n");
                   }
                
                   // Restore initial caret position in active file.
                   UltraEdit.activeDocument.gotoLine(nLine,nColumn);
                }
                
                
                // Are the list file data not loaded already from active file?
                if (asListFileData == null)
                {
                   // Is a list file name not predefined in script file, let
                   // user of script open any file and hope it is the list file.
                   if (!sListFile.length)
                   {
                      var nDocCount = UltraEdit.document.length;
                      UltraEdit.open("");
                
                      // Has the user opened an additional file at all?
                      if (UltraEdit.document.length > nDocCount)
                      {
                         // Get the lines in active file into a string array.
                         UltraEdit.activeDocument.selectAll();
                         if (UltraEdit.activeDocument.isSel())
                         {
                            asListFileData = UltraEdit.activeDocument.selection.split("\r\n");
                         }
                         // Close the opened list file no longer needed.
                         UltraEdit.closeFile(UltraEdit.activeDocument.path,2);
                      }
                   }
                   else  // The name of the list file with full path is predefined in script.
                   {
                      var nDocCount = UltraEdit.document.length;
                      var sFileNameWithPath = sListFile.toLowerCase();
                
                      for (var nDocIndex = 0; nDocIndex < nDocCount; nDocIndex++)
                      {
                         // Is the list file opened already in UltraEdit?
                         if (UltraEdit.document[nDocIndex].path.toLowerCase() == sFileNameWithPath)
                         {
                            // Get caret position in opened list file.
                            var nLine = UltraEdit.document[nDocIndex].currentLineNum;
                            var nColumn = UltraEdit.document[nDocIndex].currentColumnNum;
                            if (bOldVersion) nColumn++;
                
                            // Get the lines in opened list file into a string array.
                            UltraEdit.document[nDocIndex].selectAll();
                            if (UltraEdit.document[nDocIndex].isSel())
                            {
                               asListFileData = UltraEdit.document[nDocIndex].selection.split("\r\n");
                            }
                            UltraEdit.document[nDocIndex].gotoLine(nLine,nColumn);
                            break;
                         }
                      }
                
                      // Is the list file not opened already?
                      if (nDocIndex == nDocCount)
                      {
                         UltraEdit.open(sListFile);
                         // Could the file be opened successfully?
                         if (UltraEdit.document.length > nDocIndex)
                         {
                            // Get the lines in active file into a string array.
                            UltraEdit.activeDocument.selectAll();
                            if (UltraEdit.activeDocument.isSel())
                            {
                               asListFileData = UltraEdit.activeDocument.selection.split("\r\n");
                            }
                            UltraEdit.closeFile(UltraEdit.activeDocument.path,2);
                         }
                      }
                   }
                }
                
                // Are the list file data loaded from active, predefined or specified list file?
                if (asListFileData != null)
                {
                   var bCreatedNewFile = false;
                
                   // Is a directory path not predefined in script file, ask user
                   // of the script for the directory path of the files to modify.
                   while (!sDirectory.length)
                   {
                      if (UltraEdit.document.length < 1)
                      {
                         UltraEdit.newFile();
                         bCreatedNewFile = true;
                      }
                      sDirectory = UltraEdit.getString("Enter directory path of files to modify:",1);
                   }
                   // Make sure the directory path ends with a backslash.
                   if (sDirectory[sDirectory.length-1] != '\\') sDirectory += '\\';
                
                   // Is the file name pattern not predefined in script file, ask
                   // user of the script for the file extension/file name pattern.
                   while (!sFileExtension.length)
                   {
                      if (UltraEdit.document.length < 1)
                      {
                         UltraEdit.newFile();
                         bCreatedNewFile = true;
                      }
                      sFileExtension = UltraEdit.getString("Enter file name pattern (extension) like *.htm:",1);
                   }
                
                   // Define the replace in files options never modified.
                   UltraEdit.frInFiles.filesToSearch = 0;
                   UltraEdit.frInFiles.searchSubs = false;
                   UltraEdit.frInFiles.directoryStart = sDirectory;
                   UltraEdit.frInFiles.searchInFilesTypes = sFileExtension;
                   UltraEdit.frInFiles.openMatchingFiles = false;
                   UltraEdit.frInFiles.ignoreHiddenSubs = true;
                   UltraEdit.frInFiles.logChanges = true;
                   UltraEdit.frInFiles.matchWord = false;
                   UltraEdit.frInFiles.preserveCase = false;
                   UltraEdit.frInFiles.useEncoding = true;
                   UltraEdit.frInFiles.encoding = 65001;
                
                // ***** new update start *****
                
                 UltraEdit.outputWindow.clear();
                 UltraEdit.frInFiles.useOutputWindow=true;
                 UltraEdit.frInFiles.find('');
                 UltraEdit.outputWindow.copy();
                 UltraEdit.newFile();
                 UltraEdit.activeDocument.paste();
                 UltraEdit.clearClipboard();
                 UltraEdit.selectClipboard(0);
                 UltraEdit.activeDocument.top();
                
                 UltraEdit.perlReOn();
                 UltraEdit.activeDocument.findReplace.mode=0;
                 UltraEdit.activeDocument.findReplace.matchCase=false;
                 UltraEdit.activeDocument.findReplace.matchWord=false;
                 UltraEdit.activeDocument.findReplace.regExp=true;
                 UltraEdit.activeDocument.findReplace.searchDown=true;
                 UltraEdit.activeDocument.findReplace.replaceAll=true;
                 UltraEdit.activeDocument.findReplace.replaceInAllOpen=false;
                
                 UltraEdit.activeDocument.top();
                 UltraEdit.activeDocument.findReplace.replace("^Search complete, found.+\\r\\n","");
                 UltraEdit.activeDocument.findReplace.replace("^(.+.)\\.(\\w+)$","copy \\1\.\\2 \\1\.bak");
                 var batFile = "c:\\temp\\bak.bat";
                 var toolName = "backup";
                 var nPath = UltraEdit.activeDocument.selection;
                 nPath = nPath.replace(/\\/g,"\\\\");
                
                 UltraEdit.saveAs(batFile);
                 UltraEdit.closeFile(UltraEdit.activeDocument.path,2);
                
                 UltraEdit.runTool(toolName);
                
                 UltraEdit.outputWindow.clear();
                
                // ***** new update end *****
                
                   for (var nLine = 0; nLine < asListFileData.length; nLine++)
                   {
                      // Is the active line in array empty, skip the line.
                      if (!asListFileData[nLine].length) continue;
                      // Split the line up into data strings
                      var asData = asListFileData[nLine].split('\t');
                      // Skip the line on less than 2 tab characters.
                      if (asData.length < 3) continue;
                      // Skip the line on search string is an empty string.
                      if (!asData[0].length) continue;
                
                      // Determine the variable replace in files options for next execution.
                      var bApplyWorkaround = true;
                      var sOptions = asData[1].toLowerCase();
                      if (sOptions == "i")
                      {
                         UltraEdit.frInFiles.regExp = true;
                         UltraEdit.frInFiles.matchCase = true;
                         UltraEdit.perlReOn();
                         bApplyWorkaround = false;
                      }
                      else if ((sOptions == "iu") || (sOptions == "ui"))
                      {
                         UltraEdit.frInFiles.regExp = true;
                         UltraEdit.frInFiles.matchCase = true;
                         UltraEdit.ueReOn();
                      }
                      else if (sOptions == "u")
                      {
                         UltraEdit.frInFiles.regExp = true;
                         UltraEdit.frInFiles.matchCase = false;
                         UltraEdit.ueReOn();
                      }
                      else if (sOptions == "r")
                      {
                         UltraEdit.frInFiles.regExp = false;
                         UltraEdit.frInFiles.matchCase = false;
                         UltraEdit.ueReOn();
                      }
                      else if ((sOptions == "ir") || (sOptions == "ri"))
                      {
                         UltraEdit.frInFiles.regExp = false;
                         UltraEdit.frInFiles.matchCase = true;
                         UltraEdit.ueReOn();
                      }
                      else
                      {
                         UltraEdit.frInFiles.regExp = true;
                         UltraEdit.frInFiles.matchCase = false;
                         UltraEdit.perlReOn();
                         bApplyWorkaround = false;
                      }
                
                      // Output find and replace string in output window.
                      UltraEdit.outputWindow.write('Find: "' + asData[0] + '" Replace: "' + asData[2] + '"');
                
                      // Workaround for a bug in older versions of UE and UES which do
                      // not correct interpret ^p, ^r, ^n, ^t and ^b in replace string
                      // of a replace in files executed from within a script. In search
                      // string those special escape sequences are interpreted as expected.
                      if (bApplyWorkaround)
                      {
                         // Replace all ^p by carriage return + line-feed.
                         var sReplace = asData[2].replace(/\^p/g,"\r\n");
                         sReplace = sReplace.replace(/\^r/g,"\r");  // carriage return
                         sReplace = sReplace.replace(/\^n/g,"\n");  // line-feed
                         sReplace = sReplace.replace(/\^t/g,"\t");  // horizontal tab
                         sReplace = sReplace.replace(/\^b/g,"\f");  // form-feed
                         asData[2] = sReplace;
                      }
                
                      // Run the replace in files without evaluation of results.
                      UltraEdit.frInFiles.replace(asData[0],asData[2]);
                      nReplaceCount++;
                   }
                
                   // Close the new file just opened to be able to prompt user for directory
                   // path and file extension loaded into variables in older versions of UE.
                   if (bCreatedNewFile)
                   {
                      UltraEdit.closeFile(UltraEdit.activeDocument.path,2);
                   }
                   UltraEdit.clearClipboard();
                   UltraEdit.selectClipboard(0);
                }
                
                // Open the output window if any replace in files was executed at all.
                if (nReplaceCount) UltraEdit.outputWindow.showWindow(true);
                
                // Show a small summary output with number of replace in files executed.
                var sPluralS = (nReplaceCount != 1) ? "s" : "";
                UltraEdit.messageBox("Executed " + nReplaceCount + " replace" + sPluralS + " in files.");
                
                //***** new update start *****
                
                 UltraEdit.outputWindow.copy();
                 UltraEdit.newFile();
                 UltraEdit.activeDocument.top();
                 UltraEdit.activeDocument.paste();
                 UltraEdit.clearClipboard();
                 UltraEdit.selectClipboard(0);
                
                 UltraEdit.activeDocument.top();
                 UltraEdit.insertMode();
                 if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
                 else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
                 UltraEdit.perlReOn();
                 UltraEdit.activeDocument.findReplace.mode=0;
                 UltraEdit.activeDocument.findReplace.matchCase=true;
                 UltraEdit.activeDocument.findReplace.matchWord=false;
                 UltraEdit.activeDocument.findReplace.regExp=true;
                 UltraEdit.activeDocument.findReplace.searchDown=true;
                 UltraEdit.activeDocument.findReplace.replaceAll=true;
                 UltraEdit.activeDocument.findReplace.replaceInAllOpen=false;
                
                 UltraEdit.activeDocument.findReplace.replace("Find: \"([^\r\n]*?)\" Replace: \"([^\r\n]*?)\"\\r\\n0 items replaced in 0 files\\.","@@\\1\\t\\t\\2");
                 UltraEdit.activeDocument.findReplace.replace("^[^@].+\\r\\n","");
                 UltraEdit.activeDocument.findReplace.replace("^@+","");
                
                //***** new update end *****
                
                It will be my pleasure to have your kind cooperation in future.

                Thanks

                  Jan 09, 2018#8

                  Hi Mofi

                  There are once more update required for the script:

                  My requirement is some replace done by loop
                  so
                  one more environment L|l add  for loop which is defined between the tabs

                  Please can the script be updated

                  Thanks

                  6,681583
                  Grand MasterGrand Master
                  6,681583

                    Jan 10, 2018#9

                    See updated script in my first post. An optional fourth tab separated value after the replace string is interpreted as loop count value to run the Replace in Files more than once.

                    For the future please use the Post Reply button at top or bottom of a topic page and not the Reply with quote button inside a post. Thanks.
                    Best regards from an UC/UE/UES for Windows user from Austria