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

  • Home
  • SEARCH
  • 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 539975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:11:32+00:00 2026-05-13T10:11:32+00:00

Im have a xml config file called solrconfig.xml, it has this section in the

  • 0

Im have a xml config file called solrconfig.xml, it has this section in the middle of it:

<!--############ BEGIN replication settings DO NOT EDIT ################################-->
<requestHandler name="/replication" class="solr.ReplicationHandler" >
<lst name="master">
  <str name="replicateAfter">commit</str>
  <str name="replicateAfter">startup</str>
  <str name="confFiles">schema.xml,stopwords.txt</str>
</lst>
</requestHandler>
<!--############ END replication settings DO NOT EDIT ################################-->

I have a shell script that I want to use to replace this section in the case I am configuring the server as a slave. I have it working, except it puts the new section at the end of the file instead of the same place as the old one, can you help me tweak this to replace it in the same spot.

if [ -n "$1" ] && [ $1 == "slave" ] 
then
    rm solrconfig2.xml
    echo "setting up slave"
    cat solrconfig.xml | awk '
/^<!--############ BEGIN replication/ { skip = 1 }
/^<!--############ END replication/   { skip = 0; next; }
{ if (skip == 0) print $0; }
END {
   print "<!--############ BEGIN replication settings DO NOT EDIT ################################-->"
   print "<requestHandler name=\"/replication\" class=\"solr.ReplicationHandler\" >"
   print "<lst name=\"slave\">"
   print "<str name=\"masterUrl\">http://solr-master:8983/solr/replication</str>"
   print "<str name=\"pollInterval\">00:00:60</str>"
   print "</lst>"
   print "</requestHandler>"
   print "<!--############ END replication settings DO NOT EDIT ################################-->"
}
' > solrconfig2.xml
fi
  • 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-13T10:11:33+00:00Added an answer on May 13, 2026 at 10:11 am

    In your block for the beginning of the region ({ skip = 1}), add your print statements there. The logic is:

    if this is the beginning of the special block:
        set a flag
        print my replacement
    
    if this is the end of the special block:
       unset a flag
    
    else if the flag is not set:
       print the current line
    

    The solution looks something like this:

    if [ -n "$1" ] && [ $1 == "slave" ] 
    then
        rm solrconfig2.xml
        echo "setting up slave"
        cat solrconfig.xml | awk '
    /^<!--############ BEGIN replication/ { 
       skip = 1 
       print "<!--############ BEGIN replication settings DO NOT EDIT ################################-->"
       print "<requestHandler name=\"/replication\" class=\"solr.ReplicationHandler\" >"
       print "<lst name=\"slave\">"
       print "<str name=\"masterUrl\">http://solr-master:8983/solr/replication</str>"
       print "<str name=\"pollInterval\">00:00:60</str>"
       print "</lst>"
       print "</requestHandler>"
       print "<!--############ END replication settings DO NOT EDIT ################################-->"
    }
    /^<!--############ END replication/   { skip = 0; next; }
    { if (skip == 0) print $0; }
    ' > solrconfig2.xml
    fi
    

    However, a better solution might be to use a better scripting language with XML support (for example, Python, Ruby or Tcl) and take advantage of the ability to manipulate the DOM.

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

Sidebar

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.