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 8018399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:07:11+00:00 2026-06-04T21:07:11+00:00

I am looking to write a bash script for something slightly more complicated than

  • 0

I am looking to write a bash script for something slightly more complicated than the usual find/replace via sed. I have a book called bash Cookbook that I have been trying to glean some inspiration from but I am not getting very far.

Basically I am trying to write a script to update the version numbers in a bunch of maven pom.xml files automatically. Here is the general setup I am looking at:

<!-- TEMPLATE:BEGIN
    <version>@@VERSION@@</version>
-->
    <version>1.0.0</version>
<!-- TEMPLATE:END -->

After running the script (with the new version number 1.0.1) I’d like the file to read this instead:

<!-- TEMPLATE:BEGIN
    <version>@@VERSION@@</version>
-->
    <version>1.0.1</version>
<!-- TEMPLATE:END -->

So this would be in the actual release pom file, with 1.0.0 being the current version (and I am trying to replace it with 1.0.1 or something). Obviously the version number will be changing so there isn’t a good way to do a find/replace (since the thing you want to find is variable). I am hoping to be able to write a bash script which can

  1. replace @@VERSION@@ with the actual version number
  2. delete the current version line
  3. write the updated version line on the line before the TEMPLATE:END (while preserving the @@VERSION@@ in the file – possibly do this by writing template out to a temp file, doing replacement, then back in?)

I can sort of do some of this (writing out to a new file, doing replacement) using an ant script a la
<replace file="pom.xml">
<replacefilter
token="@@VERSION@@"
value="${version}"/>
</replace>

But I am not sure what the best ways to a.) delete the line with the old version or b.) tell it to copy the new line in the correct place are. Anyone know how to do this or have any advice?

  • 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-06-04T21:07:12+00:00Added an answer on June 4, 2026 at 9:07 pm

    Assuming the new version number is in a shell variable $VERSION, then you should be able to use:

    sed -e '/<!-- TEMPLATE:BEGIN/,/<!-- TEMPLATE:END -->/{
            s/<version>[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*<\/version>/<version>'$VERSION'<\/version>/
            }'
    

    Note that this ignores the template version line with @@VERSION@@, but only matches a three-part version number that appears between the lines containing TEMPLATE:BEGIN and TEMPLATE:END, leaving everything else (including other lines containing a <version>...</version> element) alone.

    You can decide how to do file overwriting (maybe your version of sed is from GNU and it does that automatically on request with the -i option), etc. You might also be able to use more powerful regular expression notations that lead to more compact matches. However, that should work on most versions of sed without change.

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

Sidebar

Related Questions

I'm looking to write a bash script that will recursively find all .less files
Looking for some help with my bash script. I am trying to write this
I'm looking to write a simple proxy server in .NET. Does anyone have any
I am looking to write something that seems like it should be easy enough,
I am looking to write the contents of a dictionary to XML. I have
I'm looking to write a Bash one-liner that calls a function once for each
I'm trying to write a bash script that takes a file name, and return
Let's say I've got a shell script called print_error.sh looking like this: #!/usr/bin/bash echo
I'm looking to write a script that will load up a file that has
I'm trying to write a bash script and I needed to do some floating

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.