Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 537605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:56:40+00:00 2026-05-13T09:56:40+00:00

I want a sed script that I can use for 1) finding instances, and

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T09:56:41+00:00Added an answer on May 13, 2026 at 9:56 am

    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

    #my try to find every occurence of constructions like 
    # <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.
    #
    # cd jahia_virk/tomcat/webapps/ROOT/jsp/jahia/templates/virk/virk.dk
    
    
    # Printing occurences:
    # =====================
    sed -nE \
    -e '/<bean:write name="([[:alpha:]]+)"( property="([[:alpha:]]+)")( filter="false")?\/>/p' \
    -e "/<bean:write name='([[:alpha:]]+)'( property='([[:alpha:]]+)')( filter='false')?\/>/p" \
    -e '/<bean:write name="([[:alpha:]]+)"\/>/p' \
    -e "/<bean:write name='([[:alpha:]]+)'\/>/p" \
    *.jsp **/*.jsp **/*.inc  
    
    
    # Replacing occurences:
    # =====================
    sed -E -i .bak \
    -e 's/<bean:write name="([[:alpha:]]+)"( property="([[:alpha:]]+)")( filter="false")?\/>/${ \1.\3 }/g' \
    -e "s/<bean:write name='([[:alpha:]]+)'( property='([[:alpha:]]+)')( filter='false')?\/>/\${ \1.\3 }/g" \
    -e 's/<bean:write name="([[:alpha:]]+)"\/>/${ \1 }/g' \
    -e "s/<bean:write name='([[:alpha:]]+)'\/>/\${ \1 }/g" \
    *.jsp **/*.jsp **/*.inc 
    

    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
    • \w did not work for matching any word character. So I had to substitute with [[:alpha:]]
    • Substitutions in any file in any directory (*/* **/*) 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 **/*.inc

    One 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:

    <bean:write name='scriptEditor-Url'/>    
    <bean:write name='currentSite' property='homePage.url'/>
    <bean:write name="portlet" property="value" filter="false" />
    <bean:write name='<%= "optTextUrl" + id %>'/>
    

    #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 }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.