I want a sed script that I can use for 1) finding instances, and 2) printing this string:
<bean:write name='iframesrcUrl'/>
<bean:write name="iframesrcUrl"/>
<bean:write name="currentPage" property="title" filter="false"/>
or similar. name and property values can differ. property and filter attributes are optional. Both single quotes ' and double quotes " occur.
The sed command must be two headed: I want first to run one command to see what it finds.
Then I want to run the next command to make the actual replacements. The strings should be replaced with:
${ iframesrcUrl }
${ currentPage.title }
A quick grep shows there are 68 occurences in my project: grep '<bean:write name=' **/* |wc -l
What would be the easiest way to solve this?
Having learned from the other answers that partially covered my question, i ended up with the following.
(I bet it can be made shorter but it works)my try to find every occurence of constructions like
A few lessons learned:
$is reserved from the command line, so I had to escape the$sign in lines where the sed expression is within double-quotes\wdid not work for matching any word character. So I had to substitute with[[:alpha:]]*/* **/*) is a no-go for hidden system files, binary files like images, etc. I had to focus on only .jsp and .inc files for my project:*.jsp **/*.jsp **/*.incOne more word of caution: I did this on a project to move it away from old-school struts style. If you are in a similar situation be careful to review any edits manually afterwards.
Script shortcomings:
For various reasons, the following examples were not found with the script above:
#1 failed because
[[:alpha:]]did not match-(and there are also some with underscores).#2 is the same:
[[:alpha:]]does not match a dot..#4 concatenates strings inside parameter name. I could write a script to find them , but there are only four occurences in the project. The big question is what it should be replaced with. I suspect inline java does not work. and I suspect I cannot just write
${ 'optTextUrl' + id }