Bonjour,
J'utilise un script python pour remplacer un mot par un autre dans un texte (avec bash). Il fonctionne bien avec des mots anglais, mais pas avec des mots français accentués...
Voici le script :
Code Python :
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import re
from_str,to_str=sys.argv[1:3]
contents=sys.stdin.read()
pat_str=r'(?<!-)\b%s\b(?=[^-]|\Z)'%(from_str)
pat=re.compile(pat_str,re.IGNORECASE)
result=pat.sub(to_str,contents)
print(result)
Ensuite avec bash, les exemples (tordus mais prévoyants) suivants donnent :
$ echo "green-this this this this-green" | erg-replace.py "this" "yellow"
green-this yellow yellow this-green
En anglais le mot non composé "this" est donc correctement remplacé.
$ echo rouge-ça ça ça ça-vert | erg-replace.py ça jaune
rouge-ça ça ça ça-vert
En français, le caractère "ç" ne passe pas...
Merci de l'aide,
Thibaud.