-1

Input line:

<column name="Sample"><![TEST[x-y]]></column>

Output line:

<column name="Sample"><![TEST[y]]></column>

x is any number

y is any number

I want to get rid of x-. How to do it in Perl? Or maybe it's possible with sed?

Lev Levitsky
  • 63,701
  • 20
  • 147
  • 175
  • did you try parsing the input? This is not XML, specifically `<![TEST[y]]>` is not well-formed XML. So you probably shouldn't call it XML (and of course you can't use XML tools on it). – mirod Oct 10 '13 at 11:50

1 Answers1

1

This regex should do want you want:

$line=~s/(?<=<\!\[TEST\[)\d+\-//;

One-liner flavor:

perl -pe 's/(?<=<\!\[TEST\[)\d+\-//' file.xml

But, as said before in StackOverflow, avoid parsing/processing XML with the use of regular expressions. Use instead a module (eg. XML::Simple).

Community
  • 1
  • 1
psxls
  • 6,807
  • 6
  • 30
  • 50
  • 1
    *Please* don't recommend `XML::Simple`. Its own documentation says this *"The use of this module in new code is discouraged. Other modules are available which provide more straightforward and consistent interfaces."* – Borodin Oct 10 '13 at 17:47
  • Noted. It has been a long time since I had to parse any XML. Please feel free to edit my answer with more appropriate modules. – psxls Oct 10 '13 at 17:53