PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > removing rogue characters with sed
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

removing rogue characters with sed

Réponse
 
LinkBack Outils de la discussion
Vieux 27/05/2007, 17h16   #1
waffle.horn@googlemail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut removing rogue characters with sed

Hi all,

Im trying to remove two types of rogue characters but I can't seem to
think of the correct solution with sed. The characters Im trying to
remove are the @ and ` characters shown below

-0.1000@-0.1000

-0.1000`-0.1000

I have tried...

sed 's/@/ /' FILENAME | sed 's/`/ /'

It doesn't seem to work for all instances. Any idea would be much
appreciated

Many thanks.

  Réponse avec citation
Vieux 27/05/2007, 19h14   #2
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: removing rogue characters with sed

On 2007-05-27, waffle.horn@googlemail.com wrote:
> Hi all,
>
> Im trying to remove two types of rogue characters but I can't seem to
> think of the correct solution with sed. The characters Im trying to
> remove are the @ and ` characters shown below
>
> -0.1000@-0.1000
>
> -0.1000`-0.1000
>
> I have tried...
>
> sed 's/@/ /' FILENAME | sed 's/`/ /'
>
> It doesn't seem to work for all instances.


Presumably, those instances are where there's more than one such
character on a line. For that you need to use global substitution
(and you can do it with a single call to sed):

sed -e 's/@/ /g' -e 's/`/ /g' FILENAME

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
  Réponse avec citation
Vieux 27/05/2007, 19h17   #3
Andrew Smallshaw
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: removing rogue characters with sed

On 2007-05-27, waffle.horn@googlemail.com <waffle.horn@googlemail.com> wrote:
> Hi all,
>
> Im trying to remove two types of rogue characters but I can't seem to
> think of the correct solution with sed. The characters Im trying to
> remove are the @ and ` characters shown below
>
> -0.1000@-0.1000
>
> -0.1000`-0.1000
>
> I have tried...
>
> sed 's/@/ /' FILENAME | sed 's/`/ /'


You probably weant the 'g' option to s to make the replacements
global. Without it sed will only replace the first occurance.

You also don't need to call sed twice like this. You can feed sed
more than one command at a time, or in this instance combine the
commands into one:

sed 's/[@`]/ /g' FILENAME

That will replace either a "@" or "`" with spaces like your example
above did. To actually delete them, replace the command to sed
with 's/[@`]//g'

--
Andrew Smallshaw
andrews@sdf.lonestar.org
  Réponse avec citation
Vieux 27/05/2007, 20h06   #4
John W. Krahn
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: removing rogue characters with sed

waffle.horn@googlemail.com wrote:
>
> Im trying to remove two types of rogue characters but I can't seem to
> think of the correct solution with sed. The characters Im trying to
> remove are the @ and ` characters shown below
>
> -0.1000@-0.1000
>
> -0.1000`-0.1000
>
> I have tried...
>
> sed 's/@/ /' FILENAME | sed 's/`/ /'
>
> It doesn't seem to work for all instances. Any idea would be much
> appreciated


If you want to remove them:

tr -d '@`' < FILENAME

If you want to replace them with a space like your example shows:

tr '@`' ' ' < FILENAME



John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
  Réponse avec citation
Vieux 27/05/2007, 23h38   #5
badger
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: removing rogue characters with sed

Thank you both examples seemed to do the trick. The is much
appreciated as are the explanations.

On May 27, 8:06 pm, "John W. Krahn" <some...@example.com> wrote:
> waffle.h...@googlemail.com wrote:
>
> > Im trying to remove two types of rogue characters but I can't seem to
> > think of the correct solution with sed. The characters Im trying to
> > remove are the @ and ` characters shown below

>
> > -0.1...@-0.1000

>
> > -0.1000`-0.1000

>
> > I have tried...

>
> > sed 's/@/ /' FILENAME | sed 's/`/ /'

>
> > It doesn't seem to work for all instances. Any idea would be much
> > appreciated

>
> If you want to remove them:
>
> tr -d '@`' < FILENAME
>
> If you want to replace them with a space like your example shows:
>
> tr '@`' ' ' < FILENAME
>
> John
> --
> Perl isn't a toolbox, but a small machine shop where you can special-order
> certain sorts of tools at low cost and in short order. -- Larry Wall



  Réponse avec citation
Vieux 27/05/2007, 23h41   #6
waffle.horn@googlemail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: removing rogue characters with sed

Thank you both examples seemed to do the trick. The is much
appreciated as are the explanations.

On May 27, 8:06 pm, "John W. Krahn" <some...@example.com> wrote:
> waffle.h...@googlemail.com wrote:
>
> > Im trying to remove two types of rogue characters but I can't seem to
> > think of the correct solution with sed. The characters Im trying to
> > remove are the @ and ` characters shown below

>
> > -0.1...@-0.1000

>
> > -0.1000`-0.1000

>
> > I have tried...

>
> > sed 's/@/ /' FILENAME | sed 's/`/ /'

>
> > It doesn't seem to work for all instances. Any idea would be much
> > appreciated

>
> If you want to remove them:
>
> tr -d '@`' < FILENAME
>
> If you want to replace them with a space like your example shows:
>
> tr '@`' ' ' < FILENAME
>
> John
> --
> Perl isn't a toolbox, but a small machine shop where you can special-order
> certain sorts of tools at low cost and in short order. -- Larry Wall



  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 22h17.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,12818 seconds with 14 queries