Change 2 values in 2 different lines

Hello all,

I have a file looks like a xml file:

....
<SrcIntDef>WAUXDFXXX<\SrcIntDef>
<SrcIntRep>WUBGIUNXXX<\SrcIntRep>
...

For these 2 lines I will change the values. So for result it should look like:

...
<SrcIntDef>WUBGIUNXXX<\SrcIntDef>
<SrcIntRep>WAUXDFXXX<\SrcIntRep>
...

How should I realize this?

Tx in advance.

Just use a regular expression with your favorite text process tool / utility / programming language.

For example, with your given sample this should work:

sed '/<SrcIntDef>/{N; s/\(>[^<]*<\)\(.*\)\(>[^<]*<\)/\3\2\1/;}' file

But whether that is usable for you depends on more precise specification of what you require exactly and what variations of the input file must be tolerated, for example:

  • Are the two values that need to be switched always on two adjacent lines or is that variable like xml allows?
  • Are they in that exact order or is that variable?
  • Do you want to flip whatever is between those tags?
  • Do you want the values to flip when they have specific values?
  • Do you want the values to flip when they have specific values, no matter within what tags they appear?

Tx for this answer. I will check this.

As Scrutinizer already stated, you need to be way more specific. One option would be

sed '/<SrcInt/ {s/Def/\o001/g; s/Rep/Def/g; s/\o001/Rep/g}' file
<SrcIntRep>WAUXDFXXX<\SrcIntRep>
<SrcIntDef>WUBGIUNXXX<\SrcIntDef>