Skip to main content
added 72 characters in body
Source Link
Gilles Quénot
  • 36.6k
  • 7
  • 74
  • 97

Using xmlstarlet as shell commands, in 2 calls of this utility:

#!/bin/sh
 
xmlstarlet sel -t -v '//table/search/query/text()' file.xml > /tmp/temp.txt
grep 'index=restricted_security' /tmp/temp.txt || exit 0
xmlstarlet ed -u '//table/search/query' -v "index=NEW_NAME
$(awk 'NR>1' /tmp/temp.txt)" file.xml

You can add the -L switch to xmlstarlet ed if you need to edit in place.

You can even edit the /tmp/temp.txt file with sed if needed:

(this is not XML but text after the first execution of xmlstarlet)

#!/bin/sh
 
xmlstarlet sel -t -v '//table/search/query/text()' file.xml > /tmp/temp.txt
sed -i 's/index=restricted_security/index=NEW_NAME/' /tmp/temp.txt
xmlstarlet ed -u '//table/search/query' -v "$(</tmp/temp.txt)" file.xml

Using xmlstarlet as shell commands, in 2 calls of this utility:

#!/bin/sh
 
xmlstarlet sel -t -v '//table/search/query/text()' file.xml > /tmp/temp.txt
grep 'index=restricted_security' /tmp/temp.txt || exit 0
xmlstarlet ed -u '//table/search/query' -v "index=NEW_NAME
$(awk 'NR>1' /tmp/temp.txt)" file.xml

You can add the -L switch to xmlstarlet ed if you need to edit in place.

You can even edit the /tmp/temp.txt file with sed if needed:

#!/bin/sh
 
xmlstarlet sel -t -v '//table/search/query/text()' file.xml > /tmp/temp.txt
sed -i 's/index=restricted_security/index=NEW_NAME/' /tmp/temp.txt
xmlstarlet ed -u '//table/search/query' -v "$(</tmp/temp.txt)" file.xml

Using xmlstarlet as shell commands, in 2 calls of this utility:

#!/bin/sh
 
xmlstarlet sel -t -v '//table/search/query/text()' file.xml > /tmp/temp.txt
grep 'index=restricted_security' /tmp/temp.txt || exit 0
xmlstarlet ed -u '//table/search/query' -v "index=NEW_NAME
$(awk 'NR>1' /tmp/temp.txt)" file.xml

You can add the -L switch to xmlstarlet ed if you need to edit in place.

You can even edit the /tmp/temp.txt file with sed if needed:

(this is not XML but text after the first execution of xmlstarlet)

#!/bin/sh
 
xmlstarlet sel -t -v '//table/search/query/text()' file.xml > /tmp/temp.txt
sed -i 's/index=restricted_security/index=NEW_NAME/' /tmp/temp.txt
xmlstarlet ed -u '//table/search/query' -v "$(</tmp/temp.txt)" file.xml
added 5 characters in body
Source Link
Gilles Quénot
  • 36.6k
  • 7
  • 74
  • 97

Using xmlstarlet as shell commands, in 2 calls of this utility:

Using xmlstarlet as shell commands, in 2 calls of this utility:

#!/bin/sh
 
xmlstarlet sel -t -v '//table/search/query/text()' file.xml > /tmp/temp.txt
grep 'index=restricted_security' /tmp/temp.txt || exit 0
xmlstarlet ed -u '//table/search/query' -v "index=NEW_NAME
$(awk 'NR>1' /tmp/temp.txt)" file.xml

You can add the -L switch to xmlstarlet ed if you need to edit in place.

You can even edit the /tmp/temp.txt file with sed if needed:

You can even edit the /tmp/temp.txt file with sed if needed:

#!/bin/sh
 
xmlstarlet sel -t -v '//table/search/query/text()' file.xml > /tmp/temp.txt
sed -i 's/index=restricted_security/index=NEW_NAME/' /tmp/temp.txt
xmlstarlet ed -u '//table/search/query' -v "$(</tmp/temp.txt)" file.xml

Using xmlstarlet as shell commands, in 2 calls of this utility:

#!/bin/sh
 
xmlstarlet sel -t -v '//table/search/query/text()' file.xml > /tmp/temp.txt
grep 'index=restricted_security' /tmp/temp.txt || exit 0
xmlstarlet ed -u '//table/search/query' -v "index=NEW_NAME
$(awk 'NR>1' /tmp/temp.txt)" file.xml

You can add the -L switch to xmlstarlet ed if you need to edit in place.

You can even edit the /tmp/temp.txt file with sed if needed:

#!/bin/sh
 
xmlstarlet sel -t -v '//table/search/query/text()' file.xml > /tmp/temp.txt
sed -i 's/index=restricted_security/index=NEW_NAME/' /tmp/temp.txt
xmlstarlet ed -u '//table/search/query' -v "$(</tmp/temp.txt)" file.xml

Using xmlstarlet as shell commands, in 2 calls of this utility:

#!/bin/sh
 
xmlstarlet sel -t -v '//table/search/query/text()' file.xml > /tmp/temp.txt
grep 'index=restricted_security' /tmp/temp.txt || exit 0
xmlstarlet ed -u '//table/search/query' -v "index=NEW_NAME
$(awk 'NR>1' /tmp/temp.txt)" file.xml

You can add the -L switch to xmlstarlet ed if you need to edit in place.

You can even edit the /tmp/temp.txt file with sed if needed:

#!/bin/sh
 
xmlstarlet sel -t -v '//table/search/query/text()' file.xml > /tmp/temp.txt
sed -i 's/index=restricted_security/index=NEW_NAME/' /tmp/temp.txt
xmlstarlet ed -u '//table/search/query' -v "$(</tmp/temp.txt)" file.xml
added 317 characters in body
Source Link
Gilles Quénot
  • 36.6k
  • 7
  • 74
  • 97

Using xmlstarlet as shell commands, in 2 calls of this utility:

#!/bin/sh
 
xmlstarlet sel -t -v '//table/search/query/text()' file.xml > /tmp/temp.txt
grep 'index=restricted_security' /tmp/temp.txt || exit 0
xmlstarlet ed -u '//table/search/query' -v "index=NEW_NAME
$(awk 'NR>1' /tmp/temp.txt)" file.xml

You can add the -L switch to xmlstarlet ed if you need to edit in place.

You can even edit the /tmp/temp.txt file with sed if needed:

#!/bin/sh
 
xmlstarlet sel -t -v '//table/search/query/text()' file.xml > /tmp/temp.txt
sed -i 's/index=restricted_security/index=NEW_NAME/' /tmp/temp.txt
xmlstarlet ed -u '//table/search/query' -v "$(</tmp/temp.txt)" file.xml

Using xmlstarlet as shell commands, in 2 calls of this utility:

#!/bin/sh
 
xmlstarlet sel -t -v '//table/search/query/text()' file.xml > /tmp/temp.txt
grep 'index=restricted_security' /tmp/temp.txt || exit 0
xmlstarlet ed -u '//table/search/query' -v "index=NEW_NAME
$(awk 'NR>1' /tmp/temp.txt)" file.xml

You can add the -L switch to xmlstarlet ed if you need to edit in place.

Using xmlstarlet as shell commands, in 2 calls of this utility:

#!/bin/sh
 
xmlstarlet sel -t -v '//table/search/query/text()' file.xml > /tmp/temp.txt
grep 'index=restricted_security' /tmp/temp.txt || exit 0
xmlstarlet ed -u '//table/search/query' -v "index=NEW_NAME
$(awk 'NR>1' /tmp/temp.txt)" file.xml

You can add the -L switch to xmlstarlet ed if you need to edit in place.

You can even edit the /tmp/temp.txt file with sed if needed:

#!/bin/sh
 
xmlstarlet sel -t -v '//table/search/query/text()' file.xml > /tmp/temp.txt
sed -i 's/index=restricted_security/index=NEW_NAME/' /tmp/temp.txt
xmlstarlet ed -u '//table/search/query' -v "$(</tmp/temp.txt)" file.xml
Added prettify hint
Source Link
Toby Speight
  • 9.3k
  • 3
  • 32
  • 54
Loading
added 46 characters in body
Source Link
Gilles Quénot
  • 36.6k
  • 7
  • 74
  • 97
Loading
Source Link
Gilles Quénot
  • 36.6k
  • 7
  • 74
  • 97
Loading