View previous topic :: View next topic |
Author |
Message |
luteola Tux's lil' helper
Joined: 03 Mar 2006 Posts: 118 Location: Bruxelles
|
Posted: Mon Oct 02, 2006 8:37 pm Post subject: [bash] question sur sed |
|
|
salut
Dans plusieurs fichiers, je cherche à remplacer une chaîne de caractères
par
Hélas, un
Code: | sed 's/pg&fr/pg.fr/g' fichier > fichier.new
|
ne fonctionne pas Le caractère & est mal interprété. J'ai bien essayé de le protéger par un \ mais rien n'y fait. J'ai tout essayé : mettre en variable, faire un `echo variable` à la place etc rien n'y fait
une idée ??
merci !
a+ _________________ www.guidelinux.org
________________________________________
Gentoo amd64 2007.0
Asus A8N32-SLI
AMD Athlon 4000+, 2Go DDR400
NVIDIA 7900GTX
Soundblaster Audigy 4 |
|
Back to top |
|
|
Ascodas Apprentice
Joined: 18 Nov 2004 Posts: 263
|
Posted: Mon Oct 02, 2006 9:12 pm Post subject: |
|
|
Pourtant chez moi :
Quote: | [thomas@amd64 scripts]$ cat essai.txt
pg&fr
[thomas@amd64 scripts]$ sed 's/pg\&fr/pg.fr/g' essai.txt > essai.txt.ok
[thomas@amd64 scripts]$ cat essai.txt.ok
pg.fr
[thomas@amd64 scripts]$ |
Ton idée de protéger le & est bonne. |
|
Back to top |
|
|
truc Advocate
Joined: 25 Jul 2005 Posts: 3199
|
Posted: Mon Oct 02, 2006 9:13 pm Post subject: |
|
|
euh Code: | $ cat test
pg&fr
$ cat test | sed 's/pg&fr/pg.fr/'
pg.fr
|
ça marche ici,j'comprends pas trop ton problème?
EDIT: grilled, note que je n'ai même pas besoin d'échapper le & _________________ The End of the Internet! |
|
Back to top |
|
|
luteola Tux's lil' helper
Joined: 03 Mar 2006 Posts: 118 Location: Bruxelles
|
Posted: Mon Oct 02, 2006 9:29 pm Post subject: |
|
|
salut
je viens de me rendre qu'effectivement ca marche. Le truc c'est que je lancais la commande sur tout plein de fichiers. Et que bizarrement, une chaine à remplacer est restée. C'est pour ca que je pensais que ca fonctionnait pas. En fait ca fonctionne à 99%. Je continue mes petites recherches pour comprendre. Merci pour votre aide.
a+ _________________ www.guidelinux.org
________________________________________
Gentoo amd64 2007.0
Asus A8N32-SLI
AMD Athlon 4000+, 2Go DDR400
NVIDIA 7900GTX
Soundblaster Audigy 4 |
|
Back to top |
|
|
truc Advocate
Joined: 25 Jul 2005 Posts: 3199
|
Posted: Mon Oct 02, 2006 10:19 pm Post subject: |
|
|
si la chaine à remplacer apparait plusieurs fois sur une même ligne alors ne pas oublier l'option 'g' 's/pg&fr/pg.fr/g' _________________ The End of the Internet! |
|
Back to top |
|
|
|