0

我需要以这种格式创建一个文件:

item0000001
item0000002
item0000003
item0000004
item0000005

我正在使用 UltraEdit 执行此操作,它的列模式包括插入编号(开始 + 增量包括前导零)。

不幸的是,UltraEdit 爆炸了超过 100 万行。

有谁知道具有类似操作的大文件容量的文本编辑器?

4

1 回答 1

0

BaltoStar 没有写出使用了哪个版本的 UltraEdit,以及他究竟是如何尝试创建文件的。

但是,这里有一个 UltraEdit 脚本,它可以用来创建一个文件,其中的行包含一个递增的数字,根据最后一个数字带有前导零。

要将该脚本与 UltraEdit v14.20 或 UEStudio v9.00 或任何更高版本一起使用,请复制脚本的代码块并将其粘贴到 UltraEdit/UEStudio 中带有 DOS 行终止的新 ASCII 文件中。例如,将文件保存为CreateLinesWithIncrementingNumber.js到您首选的 UE/UES 脚本目录中。

现在通过单击菜单Scripting中的菜单项Run Active Script来运行脚本。

该脚本提示用户输入递增数字的第一个和最后一个值,以及递增数字的左侧和右侧的字符串,这些字符串也可以是空字符串。

然后向后倾斜,看看脚本如何将带有递增数字的行写入块中的新文件中。我使用这个 UltraEdit 脚本在几秒钟内创建了一个超过 150 MB 的文件,其数字从 0 递增到 5.000.000。

if (typeof(UltraEdit.clipboardContent) == "string")
{
   // Write in blocks of not more than 4 MB into the file. Do not increase
   // this value too much as during the script execution much more free
   // RAM in a continous block is necessary than the value used here for
   // joining the lines in user clipboard 9. A too large value results
   // in a memory exception during script execution and the user of the
   // script also does not see for several seconds what is going on.
   var nBlockSize = 4194304;

   // Create a new file and make sure it uses DOS/Windows line terminations
   // independent on the user configuration for line endings of new files.
   UltraEdit.newFile();
   UltraEdit.activeDocument.unixMacToDos();
   var sLineTerm = "\r\n";    // Type of line termination is DOS/Windows.

   // Ask user of script for the first value to write into the file.
   do
   {
      var nFirstNumber = UltraEdit.getValue("Please enter first value of incrementing number:",1);
      if (nFirstNumber < 0)
      {
         UltraEdit.messageBox("Sorry, but first value cannot be negative.");
      }
   }
   while (nFirstNumber < 0);

   // Ask user of script for the last value to write into the file.
   do
   {
      var nLastNumber = UltraEdit.getValue("Please enter last value of incrementing number:",1);
      if (nFirstNumber >= nLastNumber)
      {
         UltraEdit.messageBox("Sorry, but last value must be greater than "+nFirstNumber.toString(10)+".");
      }
   }
   while (nFirstNumber >= nLastNumber);

   var sBeforeNumber = UltraEdit.getString("Please enter string left of the incrementing number:",1);
   var sAfterNumber = UltraEdit.getString("Please enter string right of the incrementing number:",1);

   // http://stackoverflow.com/questions/16378849/ultraedit-how-do-i-pad-out-a-string-with-leading-blanks
   // Convert the highest number to a decimal string and get a copy
   // of this string with every character replaced by character '0'.
   // With last number being 39428 the created string is "00000".
   var sLeadingZeros = nLastNumber.toString(10).replace(/./g,"0");

   // Instead of writing the string with the incrementing number line
   // by line to file which would be very slow and which would create
   // lots of undo records, the lines are collected first in an array of
   // strings whereby the number of strings in the array is determined
   // by value of variable nBlockSize. The lines in the array are
   // concatenated into user clipboard 9 and written as block to the
   // file using paste command. That is much faster and produces just
   // a few undo records even on very large files.
   UltraEdit.selectClipboard(9);
   UltraEdit.clearClipboard();

   // Calculate number of lines per block which depends on the
   // lengths of the 4 strings which build a line in the file.
   var nLineLength = sBeforeNumber.length + sLeadingZeros.length +
                     sAfterNumber.length + sLineTerm.length;
   var nRemainder = nBlockSize % nLineLength;
   var nLinesPerBlock = (nBlockSize - nRemainder) / nLineLength;

   var asLines = [];
   var nCurrentNumber = nFirstNumber;

   while (nLastNumber >= nCurrentNumber)
   {
      // Convert integer number to decimal string.
      var sNumber = nCurrentNumber.toString(10);
      // Has the decimal string of the current number less
      // characters than the decimal string of the last number?
      if (sNumber.length < sLeadingZeros.length)
      {
         // Build decimal string new with X zeros from the alignment string
         // and concatenate this leading zero string with the number string.
         sNumber = sLeadingZeros.substr(0,sLeadingZeros.length-sNumber.length) + sNumber;
      }
      asLines.push(sBeforeNumber + sNumber + sAfterNumber);
      if (asLines.length >= nLinesPerBlock)
      {
         asLines.push(""); // Results in a line termination at block end.
         UltraEdit.clipboardContent = asLines.join(sLineTerm);
         UltraEdit.activeDocument.paste();
         UltraEdit.clearClipboard();
         asLines = [];
      }
      nCurrentNumber++;
   }
   // Output also the last block.
   if (asLines.length)
   {
      asLines.push("");
      UltraEdit.clipboardContent = asLines.join(sLineTerm);
      UltraEdit.activeDocument.paste();
      UltraEdit.clearClipboard();
   }
   // Reselect the system clipboard and move caret to top of new file.
   UltraEdit.selectClipboard(0);
   UltraEdit.activeDocument.top();
}
else if(UltraEdit.messageBox)
{
   UltraEdit.messageBox("Sorry, but you need a newer version of UltraEdit/UEStudio for this script.");
}
else
{
   UltraEdit.newFile();
   UltraEdit.activeDocument.write("Sorry, but you need a newer version of UltraEdit/UEStudio for this script.");
}
于 2014-02-15T12:51:06.687 回答