From: Greg Russell on
In news:7vl6hnFd86U1(a)mid.individual.net,
Phred Phungus <Phred(a)example.invalid> typed:

>>> Why didn't they get moved like the other files, as they also match
>>> the regex.
>>
>> "*.c~" most certainly does NOT match "*.c", as the tilde is a
>> character that is not included in the regexp.
>
> Right. I was thinking that i was grep'ing with \\.c , which, I htink,
> would have been different.

That doesn't address the tilde either ... why do you repeatedly ignore the
tilde?


From: unruh on
On 2010-03-08, Phred Phungus <Phred(a)example.invalid> wrote:
> Greg Russell wrote:
>> In news:7vjla0Fid1U1(a)mid.individual.net,
>> Phred Phungus <Phred(a)example.invalid> typed:
>>
>>> I ran this command in the place where I keep my c source files, with a
>>> subdirectory named backups1. It seemed to work, but what am I to
>>> think of the files with the tilde after it?
>>>
>>> http://i46.tinypic.com/15wb2io.png
>>>
>>> Why didn't they get moved like the other files, as they also match the
>>> regex.
>>
>> "*.c~" most certainly does NOT match "*.c", as the tilde is a character that
>> is not included in the regexp.
>>
>>
>
> Right. I was thinking that i was grep'ing with \\.c , which, I htink,
> would have been different.

No. *.c* would do it. *.c? would get the ~ files but not the others,
*.c{,~} would get all the .c and the .c~ files. \\.c would not
match much of anything.

From: Phred Phungus on
Greg Russell wrote:
> In news:7vl6hnFd86U1(a)mid.individual.net,
> Phred Phungus <Phred(a)example.invalid> typed:
>
>>>> Why didn't they get moved like the other files, as they also match
>>>> the regex.
>>> "*.c~" most certainly does NOT match "*.c", as the tilde is a
>>> character that is not included in the regexp.
>> Right. I was thinking that i was grep'ing with \\.c , which, I htink,
>> would have been different.
>
> That doesn't address the tilde either ... why do you repeatedly ignore the
> tilde?
>
>

Because I've screwed up almost everything I've tried to grep in the last
week. I need to spend a week on regex's again.

--
From: Phred Phungus on
unruh wrote:
> On 2010-03-08, Phred Phungus <Phred(a)example.invalid> wrote:
>> Greg Russell wrote:
>>> In news:7vjla0Fid1U1(a)mid.individual.net,
>>> Phred Phungus <Phred(a)example.invalid> typed:
>>>
>>>> I ran this command in the place where I keep my c source files, with a
>>>> subdirectory named backups1. It seemed to work, but what am I to
>>>> think of the files with the tilde after it?
>>>>
>>>> http://i46.tinypic.com/15wb2io.png
>>>>
>>>> Why didn't they get moved like the other files, as they also match the
>>>> regex.
>>> "*.c~" most certainly does NOT match "*.c", as the tilde is a character that
>>> is not included in the regexp.
>>>
>>>
>> Right. I was thinking that i was grep'ing with \\.c , which, I htink,
>> would have been different.
>
> No. *.c* would do it. *.c? would get the ~ files but not the others,
> *.c{,~} would get all the .c and the .c~ files.

Interesting. I'm all about learning tricks like this.

> \\.c would not
> match much of anything.
>

I'm not sure:

$ gcc -D_GNU_SOURCE -Wall -Wextra a1.c -o out
$ ./out
a1.c
a1.c~
a2.c
a.c
bits6.c
bits7.c
f1.c
lc1.c
mort1.c
mort2.c
mort3.c
mort4.c
mort5.c
mort6.c
mort7.c
rd2.c
rd3.c
rd4.c
rd5.c
rd7.c
rd8.c
readdir_demo.c
rr1.c
rr2.c
rr3.c
rr4.c
rr5.c
ss1.c
ss2.c
ss3.c
winter1.c
status is 0
$ cat a1.c
#include <stdio.h>
#include <stdlib.h>
#define PATH_MAX 4096
int
main ()
{

FILE *fp;
int status;
char path[PATH_MAX];

fp = popen ("ls | grep \\.c", "r");
if (fp == NULL)
{/* Handle error */} ;
while (fgets (path, PATH_MAX, fp) != NULL)
printf ("%s", path);
status = pclose (fp);
printf ("status is %d\n", status);

return 0;
}
// gcc -D_GNU_SOURCE -Wall -Wextra a1.c -o out
$
--
fred
From: J G Miller on
On Mon, 08 Mar 2010 23:42:13 -0700, Phred Phungus wrote:

> I need to spend a week on regex's again.

You also have to understand that regular expressions can be different
from one program to another.

For example, the shell's understanding of * is different to that of
grep and sed.

In the shell, * means match any string. In grep and sed it means
zero or more repetitions of the immediately previously stated
expression.