Dealing with special characters at end of line in file

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Dealing with special characters at end of line in file

J C Nash
I am trying to fix up some image files (jpg) that have comments in them.
Unfortunately, many have had extra special characters encoded.

rdjpgcom, called from an R script, returns a comment e.g.,

"In  Alvarez Cabral street by no. 105.\\000"

I want to get rid of "\\000", but sub seems
to be giving trouble.

> sub("\\000", "", ctxt)
[1] "In  Alvarez Cabral street by no. 105.\\0"

Anyone know how to resolve this?

JN

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Dealing with special characters at end of line in file

David Carlson
Each of the backslashes need to be escaped with a backslash:

> ctxt <- "In  Alvarez Cabral street by no. 105.\\000"
> sub("\\\\000", "", ctxt)
[1] "In  Alvarez Cabral street by no. 105."

-------------------------------------------------------
David L. Carlson
Department of Anthropology
Texas A&M University

-----Original Message-----
From: R-help [mailto:[hidden email]] On Behalf Of J C Nash
Sent: Saturday, December 15, 2018 9:32 AM
To: r-help <[hidden email]>
Subject: [R] Dealing with special characters at end of line in file

I am trying to fix up some image files (jpg) that have comments in them.
Unfortunately, many have had extra special characters encoded.

rdjpgcom, called from an R script, returns a comment e.g.,

"In  Alvarez Cabral street by no. 105.\\000"

I want to get rid of "\\000", but sub seems
to be giving trouble.

> sub("\\000", "", ctxt)
[1] "In  Alvarez Cabral street by no. 105.\\0"

Anyone know how to resolve this?

JN

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Dealing with special characters at end of line in file

Bert Gunter-2
In reply to this post by J C Nash
... or used the fixed = TRUE argument.

> z <-"In  Alvarez Cabral street by no. 105.\\000"

> sub("\\000","", z, fixed = TRUE)
[1] "In  Alvarez Cabral street by no. 105."


Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Sat, Dec 15, 2018 at 7:32 AM J C Nash <[hidden email]> wrote:

> I am trying to fix up some image files (jpg) that have comments in them.
> Unfortunately, many have had extra special characters encoded.
>
> rdjpgcom, called from an R script, returns a comment e.g.,
>
> "In  Alvarez Cabral street by no. 105.\\000"
>
> I want to get rid of "\\000", but sub seems
> to be giving trouble.
>
> > sub("\\000", "", ctxt)
> [1] "In  Alvarez Cabral street by no. 105.\\0"
>
> Anyone know how to resolve this?
>
> JN
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Dealing with special characters at end of line in file

J C Nash
Many thanks. I'd misread the doc re fixed, and misunderstood the number of escapes. Sigh.

JN


On 2018-12-15 10:45 a.m., Bert Gunter wrote:

> ... or used the fixed = TRUE argument.
>
>> z <-"In  Alvarez Cabral street by no. 105.\\000"
>
>> sub("\\000","", z, fixed = TRUE)
> [1] "In  Alvarez Cabral street by no. 105."
>
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along and sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Sat, Dec 15, 2018 at 7:32 AM J C Nash <[hidden email] <mailto:[hidden email]>> wrote:
>
>     I am trying to fix up some image files (jpg) that have comments in them.
>     Unfortunately, many have had extra special characters encoded.
>
>     rdjpgcom, called from an R script, returns a comment e.g.,
>
>     "In  Alvarez Cabral street by no. 105.\\000"
>
>     I want to get rid of "\\000", but sub seems
>     to be giving trouble.
>
>     > sub("\\000", "", ctxt)
>     [1] "In  Alvarez Cabral street by no. 105.\\0"
>
>     Anyone know how to resolve this?
>
>     JN
>
>     ______________________________________________
>     [hidden email] <mailto:[hidden email]> mailing list -- To UNSUBSCRIBE and more, see
>     https://stat.ethz.ch/mailman/listinfo/r-help
>     PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>     and provide commented, minimal, self-contained, reproducible code.
>

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.