All,
I have the following files in a directory and I would like only a list of those starting with ?lld" and ending with ?dat?. I used the following and it gives me the lld files
list.files(path = readpath, pattern = "^lld[A-Z0-9]")
to get just .dat files I tried
list.files(path = readpath, pattern = "^lld[A-Z0-9].dat$?) but nothing is returned
below is a dput from the first command. $ is an end of line anchor correct? What am I doing wrong?
Best,
Glenn
c("lld022017_AB7755_AS0038.dat", "lld022017_AS0039_AS5210.dat",
"lld022017_AS5211_AS7917.dat", "lld022017_AS7918_AT8661.dat",
"lld022017_AT8662_AW6667.dat", "lld022017_AW6668_AZ3066.dat",
"lld022017_AZ3067_BC9534.dat", "lld022017_BC9535_MA2230.dat",
"lld022017_MA2231_MB0288.dat", "lld022017.zip")
help with grep list files
4 messages · Glenn Schultz, Rui Barradas, Rolf Turner +1 more
Hello, Maybe if you change the pattern to "^lld[A-Z0-9]*\\.dat$" Hope this helps, Rui Barradas Em 20-02-2017 21:41, Glenn Schultz escreveu:
All,
I have the following files in a directory and I would like only a list of those starting with ?lld" and ending with ?dat?. I used the following and it gives me the lld files
list.files(path = readpath, pattern = "^lld[A-Z0-9]")
to get just .dat files I tried
list.files(path = readpath, pattern = "^lld[A-Z0-9].dat$?) but nothing is returned
below is a dput from the first command. $ is an end of line anchor correct? What am I doing wrong?
Best,
Glenn
c("lld022017_AB7755_AS0038.dat", "lld022017_AS0039_AS5210.dat",
"lld022017_AS5211_AS7917.dat", "lld022017_AS7918_AT8661.dat",
"lld022017_AT8662_AW6667.dat", "lld022017_AW6668_AZ3066.dat",
"lld022017_AZ3067_BC9534.dat", "lld022017_BC9535_MA2230.dat",
"lld022017_MA2231_MB0288.dat", "lld022017.zip")
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org 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.
On 21/02/17 10:41, Glenn Schultz wrote:
All,
I have the following files in a directory and I would like only a list of those starting with ?lld" and ending with ?dat?. I used the following and it gives me the lld files
list.files(path = readpath, pattern = "^lld[A-Z0-9]")
to get just .dat files I tried
list.files(path = readpath, pattern = "^lld[A-Z0-9].dat$?) but nothing is returned
below is a dput from the first command. $ is an end of line anchor correct? What am I doing wrong?
Best,
Glenn
c("lld022017_AB7755_AS0038.dat", "lld022017_AS0039_AS5210.dat",
"lld022017_AS5211_AS7917.dat", "lld022017_AS7918_AT8661.dat",
"lld022017_AT8662_AW6667.dat", "lld022017_AW6668_AZ3066.dat",
"lld022017_AZ3067_BC9534.dat", "lld022017_BC9535_MA2230.dat",
"lld022017_MA2231_MB0288.dat", "lld022017.zip")
list.files(pattern="^lld.*\\.dat$") seems to work for me. cheers, Rolf
Technical Editor ANZJS Department of Statistics University of Auckland Phone: +64-9-373-7599 ext. 88276
On Mon, Feb 20, 2017 at 03:41:50PM -0600, Glenn Schultz wrote:
All, I have the following files in a directory and I would like only a list of those starting with ?lld" and ending with ?dat?. I used the following and it gives me the lld files list.files(path = readpath, pattern = "^lld[A-Z0-9]") to get just .dat files I tried list.files(path = readpath, pattern = "^lld[A-Z0-9].dat$?) but nothing is returned below is a dput from the first command. $ is an end of line anchor correct? What am I doing wrong?
Note that help(list.files) mentions (among other things):
| Note:
|
| File naming conventions are platform dependent. The pattern
| matching works with the case of file names as returned by the OS.
Also, your pattern ("^lld[A-Z0-9].dat$") does not include the '_'
character.
I was able to get the results you requested in my environment (FreeBSD
stable/11) using:
list.files(path = readpath, pattern = "^lld[_A-Z0-9]*.dat$")
(Note the '*' in there, as well.)
But "filename globbing" is not the same as "regular expressions," and as
the above-cited Note warns, results may well be platform-dependent, so
be careful.
Best, Glenn ....
Peace, david
David H. Wolfskill r at catwhisker.org How could one possibly "respect" a misogynist, racist, bullying con-man??!? See http://www.catwhisker.org/~david/publickey.gpg for my public key. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 603 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20170220/b504f5a3/attachment.bin>