Is calculation possible (search/replace) ?

Is calculation possible (search/replace) ?

2
NewbieNewbie
2

    Jul 26, 2007#1

    Hi,
    I just wanna know if this is possible
    I've a text file with numbers, example

    A=10
    B=1
    C=40

    I wanna change these numbers, wanna add or subtract let's say 10% of each number.. is this possible with Ultraedit ?

    Thank you.

    262
    MasterMaster
    262

      Jul 27, 2007#2

      No, it's not possible right out of the box.

      If You are a version 13 user, you could create a script that takes the number in each line adds or subtracts and write the result back in the line. Here is an example. Change the math part in line 5 to fit your purpose:

      Code: Select all

      // Add a function to String object, that searches for numbers (decimal point = .)
      // following an equal sign and multiply each with 1.1 (adds 10%) and round to integer.
      String.prototype.addTenPctRound = function(){
      	return this.replace(/[=]([\d.]+)/,function($0,$1) { 
      		return "="+(Math.round($1 * 1.1));	
      	});
      }
      
      var lineno = 1;
      UltraEdit.activeDocument.top();
      while (! UltraEdit.activeDocument.isEof() ) { /* loop through the file */
      	UltraEdit.activeDocument.selectLine();
      	var line = UltraEdit.activeDocument.selection; /* read selection into variable */
      
      	UltraEdit.activeDocument.write(line.addTenPctRound()); /* write line back into the editor */
      
      	UltraEdit.activeDocument.gotoLine(++lineno,1);
      }
      Another option is to choose MS Excel instead since the text file is a simple delimited file (= is the delimiter). Use Excel's "text to column" function with '=' as the delimiter. Then use whatever formulas to calculate the new values. If you need the result back in the same format, use a formula to create the '='-delimited format in a new column:
      =A1&"="&C1
      which could be copy/pasted back into a text file.

      6,681583
      Grand MasterGrand Master
      6,681583

        Jul 27, 2007#3

        Additional info: When you switch to column mode Column - Column Mode, select the columns with the values and click on Column - Sum Columns/Selection UltraEdit will open a small window with the sum of the selected values. But this command cannot be used in macros or scripts.
        Best regards from an UC/UE/UES for Windows user from Austria

        2
        NewbieNewbie
        2

          Jul 27, 2007#4

          Thank you so much.. gonna try and report back.