parsing files with "\" character

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

parsing files with "\" character

April Ettington
 Is there any way to parse files that include the \ character in a string?

When I try to use grep to extract strings with a pattern that includes "\"
it fails.

If there is no way to do it with R, is it possible with python or a bash
script?

Thank you,

April

        [[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: parsing files with "\" character

Michael Dewey-3
Dear April

Can you show us an example of what you are trying to do and how it
fails? There are rules about backspaces but I find that if one backspace
does not work try two, three, four until it works. It would be better to
understand the rules but life is short.

Michael

On 27/08/2019 06:56, April Ettington wrote:

>   Is there any way to parse files that include the \ character in a string?
>
> When I try to use grep to extract strings with a pattern that includes "\"
> it fails.
>
> If there is no way to do it with R, is it possible with python or a bash
> script?
>
> Thank you,
>
> April
>
> [[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.
>
> ---
> This email has been checked for viruses by AVG.
> https://www.avg.com
>
>

--
Michael
http://www.dewey.myzen.co.uk/home.html

______________________________________________
[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: parsing files with "\" character

Jeff Newmiller
In reply to this post by April Ettington
The principles of regex are basically the same between R and those other languages, so I don't see why you would switch... but if you did, asking here would be inappropriate.

I think the short answer is yes, but can't be specific without a reproducible example. ([1] is recommended but not required.)

Keep in mind that R has a syntax for strings that uses \ for escaping the following character. Thus, "\\" is a single-character string with a backslash in it. However, grep also uses backslash for escaping, so if you want to search for a single backslash in a target string then grep needs two backslashes, but each of those has to be escaped in an R string so you would use four backslashes in R source code strings to match one in the target.

[1] package reprex

On August 26, 2019 10:56:24 PM PDT, April Ettington <[hidden email]> wrote:

>Is there any way to parse files that include the \ character in a
>string?
>
>When I try to use grep to extract strings with a pattern that includes
>"\"
>it fails.
>
>If there is no way to do it with R, is it possible with python or a
>bash
>script?
>
>Thank you,
>
>April
>
> [[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.

--
Sent from my phone. Please excuse my brevity.

______________________________________________
[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.