Re: Replacing characters in file



Anony-mouse wrote:
In article <%7iOh.1641$Rp2.877@trndny04>, "Jürgen Exner"
<jurgenex@xxxxxxxxxxx> wrote:

Anony-mouse wrote:
In article <Z9aOh.3620$J21.675@trndny03>, "Jürgen Exner"
If on the other hand you don't have a text file, then maybe it is
time to stop treating it as a text file but start handling it as a
binary file instead.

It's not a text file. As I said it's a .DAT file

Whatever that is supposed to mean.
A file name ending of .DAT doesn't imply anything as to the content
of the file.

Although not necessarily true, it does imply that it's not a simple
.TXT file.

Well, the file ending has no bearing on the content of a file. So, yes and
so what?

that contains control
characters, including EOF ones. :o\

Well, if it is not a text file but a binary file, then it isn't very
meaningful to talk about characters.
It would have been much less confusing if you had said "I have a
two-byte sequence"01 5F" (denoted in hex) and like to replace it
with "01 5C".

Symantics (or pendaticism, whichever you prefer).

Not really. Computers are notorious at being extremely pedantic. You will
have much success when dealing with computers if you adapt a precise
language, too.

It still means the
same thing

Well, it doesn't. A character and a byte are two very different things. And
a text file and data/binary file are two very different things, too.

and some people seem to have understood what I was saying,

Some people are better in guessing than others.

while others simply want to get picky about terminology.

As I mentioned, terminology is important when dealing with something as
pedantic as computers.

I still don't understand why a simply
s/\x01\x5F/\x01\x5C/g
shouldn't work.

It doesn't work in SED because SED aborts when it hits the first EOF
character and so doesn't complete the file.

Not surprising. AFAIK SED is designed to work for text files and files that
contain text by definition don't have any content after an EOF. Do you now
realize how important the distinction between text and binary files is
sometimes?

In the version of Perl I've been using it simply does nothing - I get
a completely empty result file.

And which version would that be?
perl -v

jue

I'll have to wait until I finish
downloading Active Perl and see what happens there, but that may be
too big in filesize for my needs.


_
_/ \___
Anony-mouse says o_/O _/ \
"Eek-eek-eek!" \__/_|_/_|\____/


.



Relevant Pages

  • Re: [opensuse] amavisd warning failure?
    ... All ascii characters can be read. ... it's obvious: a binary file doesn't care about ascii ... It is up to the application program to use it or not, and even to recognize it as EOF or something else. ...
    (SuSE)
  • Re: fseek
    ... >>a text stream to a binary file or vice versa. ... >>binary file in text mode or vice versa results in undefined behavior. ... newline characters are treated the same as ... On IBM's mainframe OSs lines never have newline characters on them, ...
    (comp.lang.c)
  • Re: Replacing characters in file
    ... Well, if it is not a text file but a binary file, then it isn't very ... meaningful to talk about characters. ... It doesn't work in SED because SED aborts when it hits the first EOF ... downloading Active Perl and see what happens there, ...
    (comp.lang.perl.misc)
  • Re: Delete key leaves ghost characters at command prompt in xterm
    ... incorrect characters, and output characters to be garbled. ... remember how xterm behaved in those circumstances. ... But I am wondering if I might have cat a binary file by ... page (the pager used by man usually is configured to reset the display ...
    (comp.os.linux.misc)
  • Re: replacing text data in a binary file
    ... &HFF for the byte. ... That explains the cbyte in ... >> If you are editing a binary file I would recommend opening the file with ... >> removing or adding characters may actually corrupt the file, ...
    (microsoft.public.dotnet.languages.vb)