Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a server, and I need to change around 1200 HTML files. Is there an editor that will find and replace columns in multiple files?

Currently, I am using Notepad++ for editing, but I'm struggling with a column based search faction.

I have something like this:

 <tr>
   <td class="data"><sup>58</sup>Co</td>
   <td class="data">0.</td>
   <td class="data">70.8 d</td>
   <td class="data">2<sup>+</sup></td>
   <td class="data">+4.044(8)</td>
   <td class="data"></td>
   <td class="data">[<sup>59</sup>Co]</td>
   <td class="data">NMR/ON</td>
   <td class="data">1972Ni01</td>
 </tr>

I want to replace all <td class="data">, leaving the rest of the code untouched, with:

 <td class="isot">
 <td class="ener">
 <td class="life">
 <td class="spin">
 <td class="gfac">
 <td class="quad">
 <td class="ref_">
 <td class="meth">
 <td class="cite">

As you have noticed, the data changes to isot, ener, etc.

So I need an editor which will find and replace only the columns.

I have tried Notepad++ as I mentioned and UltraEdit but with no help. My current solution is a macro-based replace which still is very handy and I have over a thousand files to change.

share|improve this question

migrated from stackoverflow.com Dec 23 '11 at 7:24

This question came from our site for professional and enthusiast programmers.

    
This question seems valid and I don't see a reason to remove it. Please don't vandalize your post to get it removed @Kostas. This will result in your account being suspended if it continues. –  nhinkle Feb 5 '12 at 22:39

2 Answers 2

up vote 1 down vote accepted

I use SPF/SE from Command Technology. In addition to column-based editing you can exclude and find lines, then replace only within the found or excluded lines. For example, in your case I would do the following:

  1. Exclude all lines
  2. Find all occurrences of <td class="DATA"> in columns 5-22
  3. Visually verify I have the right selection
  4. Replace non-blank chars in 17-20 with spaces on non-excluded lines only
  5. Use copy/overlay to replace the blank spaces

The ability to operate only on non-excluded lines allows you to execute the change on files where the lines in question are not necessarily contiguous.

SPF/SE also has extensive scripting so once you get the sequence of commands correct, you can execute it reliably across many files.

I am not affiliated with the company. But I cut my teeth on mainframe programming using the ISPF editor, which SPF/SE is a clone of, and this is the only thing I've found in the Windows world that has the same level of native column editing. I am a Notepad++ user as well but I fall back to SPF/SE at least a couple of times a day for either column-based editing or find/replace across selected lines.


UPDATE:

I sent the SPF/SE folks a link to this question and invited them to post a better script answer. However, they were a bit cautious about vendors tooting their own horn on a site like this and instead sent me back a macro. The SPF/SE macro language is interpreted C so this may look familiar if you have coded in C. Below is their response:

Assuming the data pattern repeats exactly as described in the question, the attached macro performs the "fixup" for the entire file in a single execution. I also attached the data file that I used for testing.

If the data pattern varies by column, the macro could be modified to handle other variations not specified in the question.



Vendor's test file:

 ...random data ...
 ...random data ...
 ...random data ...
 <tr>
   <td class="data"><sup>58</sup>Co</td>
   <td class="data">0.</td>
   <td class="data">70.8 d</td>
   <td class="data">2<sup>+</sup></td>
   <td class="data">+4.044(8)</td>
   <td class="data"></td>
   <td class="data">[<sup>59</sup>Co]</td>
   <td class="data">NMR/ON</td>
   <td class="data">1972Ni01</td>
 </tr>
     ...random data ...
     ...random data ...
     ...random data ...
     ... should not find this paragraph, not starting in col 2
     <tr>
       <td class="data"><sup>58</sup>Co</td>
       <td class="data">0.</td>
       <td class="data">70.8 d</td>
       <td class="data">2<sup>+</sup></td>
       <td class="data">+4.044(8)</td>
       <td class="data"></td>
       <td class="data">[<sup>59</sup>Co]</td>
       <td class="data">NMR/ON</td>
       <td class="data">1972Ni01</td>
     </tr>
 ...random data ...
 ...random data ...
 ...random data ...
 ... should not find this paragraph, too many "data" lines
 <tr>
   <td class="data"><sup>58</sup>Co</td>
   <td class="data">0.</td>
   <td class="data">70.8 d</td>
   <td class="data">2<sup>+</sup></td>
   <td class="data">+4.044(8)</td>
   <td class="data"></td>
   <td class="data">[<sup>59</sup>Co]</td>
   <td class="data">NMR/ON</td>
   <td class="data">1972Ni01</td>
   <td class="data">1972Ni01</td>
   <td class="data">1972Ni01</td>
 </tr>
 ...random data ...
 ...random data ...
 ...random data ...
 <tr>
   <td class="data"><sup>58</sup>Co</td>
   <td class="data">0.</td>
   <td class="data">70.8 d</td>
   <td class="data">2<sup>+</sup></td>
   <td class="data">+4.044(8)</td>
   <td class="data"></td>
   <td class="data">[<sup>59</sup>Co]</td>
   <td class="data">NMR/ON</td>
   <td class="data">1972Ni01</td>
 </tr>
 ...random data ...
 ...random data ...
 ...random data ...
 <tr>
   <td class="data"><sup>58</sup>Co</td>
   <td class="data">0.</td>
   <td class="data">70.8 d</td>
   <td class="data">2<sup>+</sup></td>
   <td class="data">+4.044(8)</td>
   <td class="data"></td>
   <td class="data">[<sup>59</sup>Co]</td>
   <td class="data">NMR/ON</td>
   <td class="data">1972Ni01</td>
 </tr>
 ...random data ...
 ...random data ...
 ...random data ...
 <tr>
   <td class="data"><sup>58</sup>Co</td>
   <td class="data">0.</td>
   <td class="data">70.8 d</td>
   <td class="data">2<sup>+</sup></td>
   <td class="data">+4.044(8)</td>
   <td class="data"></td>
   <td class="data">[<sup>59</sup>Co]</td>
   <td class="data">NMR/ON</td>
   <td class="data">1972Ni01</td>
 </tr>
 ...random data ...
 ...random data ...
 ...random data ...



The actual macro:

void FixMarkup(void) {

  char *replace[];
  char *pcmd;
  char *find_str;
  int   find_count;
  int   i;
  bool  done  = FALSE;

  replace[0] = "isot";
  replace[1] = "ener";
  replace[2] = "life";
  replace[3] = "spin";
  replace[4] = "gfac";
  replace[5] = "quad";
  replace[6] = "ref_";
  replace[7] = "meth";
  replace[8] = "cite";

  while (!done) {
    SPFservice("cmd","FIND c'<tr>' 2");
    find_count = SPFservice("query","find_string_count");
    if (find_count == 1) {
      // start of paragraph "<tr>" found
      SPFservice("cmd",".A"); // label "<tr>" line as ".A"
      SPFservice("cmd","FIND c'</tr>' 2");
      find_count = SPFservice("query","find_string_count");
      if (find_count == 1) {
        // end of paragraph "</tr>" found
        SPFservice("cmd",".B"); // label "</tr>" line as ".B"
        SPFservice("cmd","LOCATE .A"); // reposition to "<tr>" line
        find_str = "c'<td class=\"data\"'";
        pcmd = strcompose("FIND ALL ",find_str," 4 .A .B");
        SPFservice("cmd",pcmd);
        find_count = SPFservice("query","find_string_count");
        if (find_count == 9) {
          //----------------------------------------------------
          // Found paragraph with the following characteristics:
          //
          //    Starts with "<tr>"  in col 2
          //    Ends   with "</tr>" in col 2
          //    Has 9 instances of '<td class="data"' in col 4
          //
          // Replace "data" in each line with appropriate text
          // from array "replace".
          //---------------------------------------------------
          i = 0;
          while (i < 9) {
            pcmd = strcompose("CHANGE c'data' '",replace[i],"' 15");
            SPFservice("cmd",pcmd);
            ++i;
          } // while
        }
      }
      }
    else {
      // No more '<tr>' paragraphs found, all done
      done = TRUE;
    }
  } // while
} // FixMarkup
share|improve this answer
    
i dont think i quite understand your steps. is there a way to script and do the whole process? Btw there are more than one selections of colum id like to change per file and that makes it hard. –  Kostas Dec 17 '11 at 17:43
    
I misunderstood the changes you wanted to make so I updated the steps. Basically, the steps find the lines to be changed, blank out the "bad" data and then fill in the blanks. The tricky part is that you want to do this in an editor with macros and/or scripting. SPF/SE has macros and the ability to launch the editor on a file to execute a macro so I'm sure this can be done, but I'm not skilled on the SPF macro facility. If the question had asked for a any solution I'd have suggested a Perl script. –  T.Rob Dec 17 '11 at 18:35
    
thank you @T.Rob i will try your macro as soon as i figure out how to run scripts and macro codes on my editor. im not a programmer my self. thank you for your time and your great post. –  Kostas Dec 17 '11 at 23:15
    
Well, I hope it helps. Sorry I don't have more experience with the tool but I tried to answer the post as written - looking for an editor that does column-based operations. Cool that the folks at Command Tech responded on the weekend though. I've always had good support from them but this was a pleasant surprise indeed! –  T.Rob Dec 18 '11 at 2:39
    
thanks again that is has been indeed really helpful. now im struggling how to run the macro. so if i havent misunderstood i have to put that code into a perl script and run it on my editor right? im following a couple of guides and i get this error: perl "$(FULL_CURRENT_PATH)" I don’t think I can run macro codes in notepad++, could you please tell me what language is that and 2-3 steps how to run the macro on my editor or another editor? thank you very much for your time @T.Rob –  Kostas Dec 18 '11 at 8:29

You can use Notepad++ to do column based editing, but you need to enable the "Multi-editing settings".

To do that,

  1. Go to Settings menu
  2. Choose Preferences.
  3. Under Editing Tab, Check mark "Enable (Ctrl+Mouse click/selection)
  4. Click on Close

Now you can use: Alt + “Left Mouse Click” for Column Mode Select

You can also try this short video, or the Kudithipudi tutorial on it

You can also use Alt + shift + arrow keys to mark a rectangular block.

So what you may do is to mark the columnar block you want to replace, then press right click and choose copy. Now paste it at the place you want to do the replacement. Now mark the columnar block that you don't want. Right click and choose delete.

share|improve this answer
    
thanks for your reply @Wishwas but how do i do a find and replace column based? find this <td class="data"> <td class="data"> <td class="data"> <td class="data"> <td class="data"> <td class="data"> <td class="data"> <td class="data"> <td class="data"> and replace with <td class="isot"> <td class="ener"> <td class="life"> <td class="spin"> <td class="gfac"> <td class="quad"> <td class="ref_"> <td class="meth"> <td class="cite"> –  Kostas Dec 17 '11 at 15:35
    
thanks for the add but how do i do that for 1200 files at the same time? thats my problem. i dont know how and when i choose my column and paste it on search/replace it doesnt find it... –  Kostas Dec 17 '11 at 16:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.