Skip to main content
added 298 characters in body
Source Link
SLePort
  • 15.5k
  • 3
  • 40
  • 45

With sed :

$ ver=3.2;
$ sed "s/\(<version>\)[^<]*\(<\/version>\)/\1$ver\2/" <<< "<version>1.7.21</version>"
<version>3.2</version>

To apply it to file :

$ ver=3.2;
$ sed -i "s/\(<version>\)[^<]*\(<\/version>\)/\1$ver\2/" file

The -i option is for editing the file in place.

Update :

To apply a sed command to a path, you must either escape the slashes in the path :

ver="\/path\/to\/fix\/CHANGE.XML";

or change the sed separator with a character you won't find in your path. Example with | :

sed "s|\(<version>\)[^<]*\(<\/version>\)|\1$ver\2|"

With sed :

$ ver=3.2;
$ sed "s/\(<version>\)[^<]*\(<\/version>\)/\1$ver\2/" <<< "<version>1.7.21</version>"
<version>3.2</version>

To apply it to file :

$ ver=3.2;
$ sed -i "s/\(<version>\)[^<]*\(<\/version>\)/\1$ver\2/" file

The -i option is for editing the file in place.

With sed :

$ ver=3.2;
$ sed "s/\(<version>\)[^<]*\(<\/version>\)/\1$ver\2/" <<< "<version>1.7.21</version>"
<version>3.2</version>

To apply it to file :

$ ver=3.2;
$ sed -i "s/\(<version>\)[^<]*\(<\/version>\)/\1$ver\2/" file

The -i option is for editing the file in place.

Update :

To apply a sed command to a path, you must either escape the slashes in the path :

ver="\/path\/to\/fix\/CHANGE.XML";

or change the sed separator with a character you won't find in your path. Example with | :

sed "s|\(<version>\)[^<]*\(<\/version>\)|\1$ver\2|"
Source Link
SLePort
  • 15.5k
  • 3
  • 40
  • 45

With sed :

$ ver=3.2;
$ sed "s/\(<version>\)[^<]*\(<\/version>\)/\1$ver\2/" <<< "<version>1.7.21</version>"
<version>3.2</version>

To apply it to file :

$ ver=3.2;
$ sed -i "s/\(<version>\)[^<]*\(<\/version>\)/\1$ver\2/" file

The -i option is for editing the file in place.