|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
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 |
|
![]() |
| Outils de la discussion | |
|
|