SED and replacing Txt Bullet

Hi Guys,

I'm sure that there is simple solution .. I googled .. it and nothing is coming up ... ( I Tried it as hex 0xE2 no luck )

sed -e 's/�/X/g' data.txt > data1.txt

I'm trying to replace bullet with X
Actually VI editor shows this sign: �

But it doesn't work - I'm sure that SED just doesn't understand bullet ...
Any ideas how to make it work.

Thank You

sed 's/\xA5/X/' data1.txt
xlm22-:Desk admin$ sed 's/\xA5/X/' data1.txt
???????
w?  123456 123456
w?  123456 123456
w?  123456 123456
w?  123456 123456

Thank You, But somehow its not working ...
Its just printing question marks

That's right ..., try something different instead:

awk '{gsub("\x95","X")}1' file
perl -pe 's/\x95/X/g' file

____
EDIT: The hex code for the bullet is \x95

Hello,

Thank You, Actually minute before you I was able to get it working using code below, Thx anyways... :slight_smile:

perl -pi -e 's/\xA5/replace/g' data.txt

question is ... I would like to save it as a script.pl

#!/usr/bin/perl

perl -pi -e 's/\xA5/replace/g' data.txt

Something like this can't be executed - I guess It needs to be formatted differently ? I would appreciate any tips

To keep the code concise ( as is ), in bash or the shell of your preference, you can do ...

#!/bin/bash

perl -pi -e 's/\xA5/replace/g' data.txt

Or if you want a pure perl script, then every step of that compact code will simply be spelled out in more detail ( a bit longer ), I can post it if you needed.

I would really appreciate that .. It would be great for future reference.

Thank You very much.

OK, here it goes...

#!/usr/bin/perl -w

open (FILE,"data");
open (TMP,">data.tmp");

while (<FILE>) {
                chomp;
                s/\x95/replace/g;
                print TMP $_ ."\n";
              }
close(FILE);
close(TMP);

rename ("data.tmp","data");

... and I'm sure that it can be refined even more.

___

... surely there is a more perlish way to do it:

#!/usr/bin/perl -w

@ARGV = ("data.txt");
$^I = ".bak"; # create a safety backup file.
while (<>) {
   s/\x95/replace/g;
   print;
           }