-1

I need to replace all the accents in the 5 vowels of the Spanish alphabet using a single replacement regex and 5 capture groups.

In my text I have áéíóúàèìòù and so on. Until now I have this regex:

s/(=?[àáÀÁ])|(=?[èéÈÉ])|(=?[ìíÌÍ])|(=?[òóÒÓ])|(=?[ùúÙÚ])/$1$2$3$4$5/g

But this regex gives me the same result on each group.

Is there a way of getting a different value on each of the different group? Like so:

group1 ($1)-> A

group2 ($2) -> E

group3 ($3) -> I

group3 ($4) -> O

group3 ($5) -> U

I know how to do this using 5 different regex, but I need to do this in just one. Any thoughts?

Thank you very much!!

Grokify
  • 15,092
  • 6
  • 60
  • 81
Sircam
  • 79
  • 1
  • 2
  • 12

1 Answers1

0

There's no way I know of to do this with one stock regular expression (though I'd love to be proved wrong.)

sed has a dedicated command y / transliterate for this kind of case:

sed -e 'y/àáÀÁèéÈÉìíÌÍòóÒÓùúÙÚ/aaAAeeEEiiIIooOOuuUU/'

However, it won't help you with removing leading = from in front of the characters you want to transliterate. Can you combine two sed commands? eg.

sed -e '{ y/àáÀÁèéÈÉìíÌÍòóÒÓùúÙÚ/AAAAEEEEIIIIOOOOUUUU/; s/=\([AEIOU]\)/\1/g; }'
Zak
  • 1,042
  • 6
  • 12
  • Thank you very much for your answer Zak. Do you know if there's a way o doing this transiteration with regular expressions using substitutions? Like this: `s/àáÀÁèéÈÉìíÌÍòóÒÓùúÙÚ/AAAAEEEEIIIIOOOOUUUU/g` Thank you for your help! – Sircam May 25 '18 at 08:15
  • @Sircam I am afraid not. This is why tools like sed and languages like Perl have transliteration commands. Rex uses Perl, so perhaps you could use Perl's `y///` command? – Zak May 25 '18 at 22:43
  • Thank you very much @Zak. I just simply wanted to replace the Spanish characters "àáÀÁèéÈÉìíÌÍòóÒÓùúÙÚ" for "aaAAeeEEiiIIooOOuuUU" and with sed as you told me, works perfectly. Now I need to figure out how (and if) Splunk is able to do this. Thanks again!! – Sircam May 28 '18 at 09:48
  • No worries, @Sircam! I've edited your post to include splunk in the title and tags. That should help you find someone who can suggest splunk-specific ways to solve your problem. – Zak May 28 '18 at 10:07
  • Thank you very much @Zak! :) – Sircam May 29 '18 at 10:40