stbtyman
Posts: 2
Joined: Thu Feb 16, 2017 6:31 pm

grep [a-zA-Z] only finds "r"

Thu Feb 16, 2017 9:39 pm

Wondering if anyone else has encountered this issue:

grep [a-zA-Z] filename
This sequence was working, but suddenly stopped (pi 3B). Now it only finds the "r" if the file contains the entire alphabet. All other grep usage seems to work fine and this usage still workes just fine on another ripi. Tried reinstalling grep and latest ripi updates. No change.

stbtyman
Posts: 2
Joined: Thu Feb 16, 2017 6:31 pm

Re: grep [a-zA-Z] only finds "r"

Fri Feb 17, 2017 4:37 pm

Suspect file corruption, but lookg for ideas where to check. Otherwise, will be reinstalling Jessie image,php, nginx... (and creating a backup image this time :D

jahboater
Posts: 5927
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: grep [a-zA-Z] only finds "r"

Fri Feb 17, 2017 4:46 pm

stbtyman wrote:Wondering if anyone else has encountered this issue:

grep [a-zA-Z] filename
This sequence was working, but suddenly stopped (pi 3B). Now it only finds the "r" if the file contains the entire alphabet. All other grep usage seems to work fine and this usage still workes just fine on another ripi. Tried reinstalling grep and latest ripi updates. No change.
The pattern [a-zA-Z] will only match a single character. I also suggest quotes to avoid interference from the shell.
Try

Code: Select all

 
grep '[a-zA-Z]*' filename
or something similar.

User avatar
Paeryn
Posts: 3008
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: grep [a-zA-Z] only finds "r"

Fri Feb 17, 2017 4:57 pm

I'd suggest quoting the search string lest the shell interprets the brackets as part of filename expansion.
You could also try using :alpha: which is equivalent to A-Za-z

Code: Select all

grep "[:alpha:]" filename
She who travels light — forgot something.

jahboater
Posts: 5927
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: grep [a-zA-Z] only finds "r"

Fri Feb 17, 2017 5:19 pm

You might need some extra brackets for that?

User avatar
drawkula
Posts: 3
Joined: Fri Dec 23, 2016 11:24 am

Re: grep [a-zA-Z] only finds "r"

Fri Feb 17, 2017 5:27 pm

Code: Select all

(yeti@kumari:21)~/xyzzy$ ls -l
total 0
...no hats with hidden rabbits...

Code: Select all

(yeti@kumari:21)~/xyzzy$ printf '%s\n' {a..e} > filename
(yeti@kumari:21)~/xyzzy$ cat filename 
a
b
c
d
e
...no hidden PIgeons too...

Code: Select all

(yeti@kumari:21)~/xyzzy$ grep [a-e] filename
a
b
c
d
e
...grepping test data behaves as expected...

Code: Select all

(yeti@kumari:21)~/xyzzy$ touch c
(yeti@kumari:21)~/xyzzy$ grep [a-e] filename
c
Boom!
"[a-e]" now expands to "c" because a file named "c" exists.

You have a file named "r" in the directory where you do your "grep"?

Return to “Troubleshooting”