NDxiak
July 21, 2009, 3:31pm
1
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
NDxiak
July 21, 2009, 4:06pm
3
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
rubin
July 21, 2009, 6:04pm
4
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
NDxiak
July 21, 2009, 6:20pm
5
Hello,
Thank You, Actually minute before you I was able to get it working using code below, Thx anyways...
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
rubin
July 21, 2009, 7:37pm
6
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.
NDxiak
July 22, 2009, 1:51pm
7
rubin:
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.
rubin
July 22, 2009, 3:12pm
8
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;
}