May be python is easier than find+awk

In Netbeans platform icons are displayed in the toolbar editor only if the underlying action have the iconBase property defined. I had more than hundred action to change when I found this bug/limitation. So I needed to add:


in all action constructors. I first tried with a find+awk/sed combo without any success. Here is the python script I used to this refactoring operation:

#! /usr/bin/python
import sys
import re
import tempfile
import os
import shutil

def do_a_file(filename):
    output, output_name = tempfile.mkstemp()
    output = os.fdopen(output, "w")
    print output_name
    rawstr = r"""(.*)putValue\(.*NAME"""
    compile_obj = re.compile(rawstr)
    for l in input:
        match_obj =
        if match_obj != None and len(match_obj.groups()) > 0:
    shutil.move(output_name, filename)

for root, subFolders, files in os.walk(sys.argv[1]):
    for file in files:
        if file.endswith(".java"):

Now I often use it with minor changes for any refactoring operations which are to specific to be supported by my favorit IDE.

Anyway I guess such multiline context search/replacement is possible with awk or sed, and I would be glad to know how.

#netbeans, #python