grep doubt

grep doubt

am 24.04.2008 15:25:23 von apogeusistemas

Hi:

Can you tell me why when I run this script I only get this output ?

solaris> cat script1

for file in `ls -R`
do
grep -iw alter $file > /apl/applprox/script1_output
grep -iw modify $file >> /apl/applprox/script1_output
grep -iw replace $file >> /apl/applprox/script1_output
done



grep: can't open OEXWFOIB.pls
grep: can't open OEXWFOIB.pls
grep: can't open OEXWFOIS.pls
grep: can't open OEXWFOIS.pls
grep: can't open OEXWFOIS.pls
grep: can't open OEXXHDRB.pls
grep: can't open OEXXHDRB.pls
grep: can't open OEXXHDRB.pls
grep: can't open OEXXHDRS.pls
grep: can't open OEXXHDRS.pls
grep: can't open OEXXHDRS.pls
grep: can't open OEXXLINB.pls
grep: can't open OEXXLINB.pls

Re: grep doubt

am 24.04.2008 15:30:03 von PK

On Thursday 24 April 2008 15:25, apogeusistemas@gmail.com wrote:

>
> Hi:
>
> Can you tell me why when I run this script I only get this output ?

(looks into the crystal ball...)

>
> solaris> cat script1
>
> for file in `ls -R`
> do
> grep -iw alter $file > /apl/applprox/script1_output
> grep -iw modify $file >> /apl/applprox/script1_output
> grep -iw replace $file >> /apl/applprox/script1_output
> done
>
>
>
> grep: can't open OEXWFOIB.pls
> grep: can't open OEXWFOIB.pls
> grep: can't open OEXWFOIS.pls
> grep: can't open OEXWFOIS.pls
> grep: can't open OEXWFOIS.pls
> grep: can't open OEXXHDRB.pls
> grep: can't open OEXXHDRB.pls
> grep: can't open OEXXHDRB.pls
> grep: can't open OEXXHDRS.pls
> grep: can't open OEXXHDRS.pls
> grep: can't open OEXXHDRS.pls
> grep: can't open OEXXLINB.pls
> grep: can't open OEXXLINB.pls

- Are you sure you fully understand the output of ls -R?
- what other output should you get? You are redirecting stdout.
- are you sure you fully understand redirection operators?

--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.

Re: grep doubt

am 24.04.2008 16:17:30 von apogeusistemas

On Apr 24, 10:30=A0am, pk wrote:
> On Thursday 24 April 2008 15:25, apogeusiste...@gmail.com wrote:
>
>
>
> > Hi:
>
> > Can you tell me why when I run this script I only get this output ?
>
> (looks into the crystal ball...)
>
>
>
>
>
>
>
> > solaris> cat script1
>
> > for file in `ls -R`
> > do
> > grep -iw alter $file > /apl/applprox/script1_output
> > grep -iw modify $file >> /apl/applprox/script1_output
> > grep -iw replace $file >> /apl/applprox/script1_output
> > done
>
> > grep: can't open OEXWFOIB.pls
> > grep: can't open OEXWFOIB.pls
> > grep: can't open OEXWFOIS.pls
> > grep: can't open OEXWFOIS.pls
> > grep: can't open OEXWFOIS.pls
> > grep: can't open OEXXHDRB.pls
> > grep: can't open OEXXHDRB.pls
> > grep: can't open OEXXHDRB.pls
> > grep: can't open OEXXHDRS.pls
> > grep: can't open OEXXHDRS.pls
> > grep: can't open OEXXHDRS.pls
> > grep: can't open OEXXLINB.pls
> > grep: can't open OEXXLINB.pls
>
> - Are you sure you fully understand the output of ls -R?
> - what other output should you get? You are redirecting stdout.
> - are you sure you fully understand redirection operators?
>
> --
> All the commands are tested with bash and GNU tools, so they may use
> nonstandard features. I try to mention when something is nonstandard (if
> I'm aware of that), but I may miss something. Corrections are welcome.- Hi=
de quoted text -
>
> - Show quoted text -


I need find all occurences of alter, modify and replace in all files,
how could I make this ?

Thank you

Re: grep doubt

am 24.04.2008 16:32:05 von Janis Papanagnou

On 24 Apr., 16:17, apogeusiste...@gmail.com wrote:
> On Apr 24, 10:30=A0am, pk wrote:
>
>
>
>
>
> > On Thursday 24 April 2008 15:25, apogeusiste...@gmail.com wrote:
>
> > > Hi:
>
> > > Can you tell me why when I run this script I only get this output ?
>
> > (looks into the crystal ball...)
>
> > > solaris> cat script1
>
> > > for file in `ls -R`
> > > do
> > > grep -iw alter $file > /apl/applprox/script1_output
> > > grep -iw modify $file >> /apl/applprox/script1_output
> > > grep -iw replace $file >> /apl/applprox/script1_output
> > > done
>
> > > grep: can't open OEXWFOIB.pls
> > > grep: can't open OEXWFOIB.pls
> > > grep: can't open OEXWFOIS.pls
> > > grep: can't open OEXWFOIS.pls
> > > grep: can't open OEXWFOIS.pls
> > > grep: can't open OEXXHDRB.pls
> > > grep: can't open OEXXHDRB.pls
> > > grep: can't open OEXXHDRB.pls
> > > grep: can't open OEXXHDRS.pls
> > > grep: can't open OEXXHDRS.pls
> > > grep: can't open OEXXHDRS.pls
> > > grep: can't open OEXXLINB.pls
> > > grep: can't open OEXXLINB.pls
>
> > - Are you sure you fully understand the output of ls -R?
> > - what other output should you get? You are redirecting stdout.
> > - are you sure you fully understand redirection operators?
>
> > --
> > All the commands are tested with bash and GNU tools, so they may use
> > nonstandard features. I try to mention when something is nonstandard (if=

> > I'm aware of that), but I may miss something. Corrections are welcome.- =
Hide quoted text -
>
> I need find all occurences of alter, modify and replace in all files,
> how could I make this ?
>
> Thank you

Somthing like...

find . -type f | xargs egrep -iw '(alter|modify|replace)' >outfile

(You need to tweak it slightly if your filenames contain e.g. spaces
and/or if your grep doesn't support option -w.)

Janis

Re: grep doubt

am 24.04.2008 16:32:53 von mallin.shetland

apogeusistemas@gmail.com scrisse:

> I need find all occurences of alter, modify and replace in all files,
> how could I make this ?

grep -R -e alter -e modify -e replace *

PS Over fifty lines of quotation before a two line post: revise
your quoting style.

--
Bottom posting sucks!

Re: grep doubt

am 24.04.2008 16:36:09 von PK

On Thursday 24 April 2008 16:17, apogeusistemas@gmail.com wrote:

> I need find all occurences of alter, modify and replace in all files,
> how could I make this ?

If you want just this (and I think you don't, at least interpreting your
previous post), then you can do

find /src/dir -type f -exec egrep 'alter|modify|replace' '{}' \;

If you need to do more things or something else, you have to be more precise
in specifying what you want.

--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.

Re: grep doubt

am 24.04.2008 17:03:07 von apogeusistemas

On Apr 24, 11:36=A0am, pk wrote:
> On Thursday 24 April 2008 16:17, apogeusiste...@gmail.com wrote:
>
> > I need find all occurences of alter, modify and replace in all files,
> > how could I make this ?
>
> If you want just this (and I think you don't, at least interpreting your
> previous post), then you can do
>
> find /src/dir -type f -exec egrep 'alter|modify|replace' '{}' \;
>
> If you need to do more things or something else, you have to be more preci=
se
> in specifying what you want.
>
> --
> All the commands are tested with bash and GNU tools, so they may use
> nonstandard features. I try to mention when something is nonstandard (if
> I'm aware of that), but I may miss something. Corrections are welcome.



Is there any ls command to show me complete file=B4s pathname ?

How could I get this ?

Thank you.

Re: grep doubt

am 24.04.2008 17:15:10 von Bill Marcum

On 2008-04-24, apogeusistemas@gmail.com wrote:
>
>
> Is there any ls command to show me complete file´s pathname ?
>
> How could I get this ?
>
Use find.

Re: grep doubt

am 24.04.2008 17:22:06 von PK

On Thursday 24 April 2008 17:03, apogeusistemas@gmail.com wrote:

>> find /src/dir -type f -exec egrep 'alter|modify|replace' '{}' \;

> Is there any ls command to show me complete file´s pathname ?
>
> How could I get this ?

There are at least two options. You can add the (nonstandard) -H option to
egrep in the above command. You can use the -l option instead, but this
prints only the filename (not the matching lines).

Or, as Janis suggested, just have find return the list of files and use
xargs to pass the list to grep. This way, grep automatically prints the
name of the file.

If you have lots of files, the latter option is probably more efficient.
Beware of files with spaces or strange characters in their name.

--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.

Re: grep doubt

am 24.04.2008 17:36:44 von PK

On Thursday 24 April 2008 16:32, mallin.shetland wrote:

> apogeusistemas@gmail.com scrisse:
>
>> I need find all occurences of alter, modify and replace in all files,
>> how could I make this ?
>
> grep -R -e alter -e modify -e replace *

Depending on your shell, this may not catch hidden files and directories at
the first level.
Also, using -F /might/ be more efficient.

--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.

Re: grep doubt

am 24.04.2008 17:41:45 von Stephane CHAZELAS

2008-04-24, 17:22(+02), pk:
> On Thursday 24 April 2008 17:03, apogeusistemas@gmail.com wrote:
>
>>> find /src/dir -type f -exec egrep 'alter|modify|replace' '{}' \;
>
>> Is there any ls command to show me complete file??s pathname ?
>>
>> How could I get this ?
>
> There are at least two options. You can add the (nonstandard) -H option to
> egrep in the above command. You can use the -l option instead, but this
> prints only the filename (not the matching lines).
[...]

Or use:

find /src/dir -type f -exec \
grep -E 'alter|modify|replace' /dev/null {} +

The "+" should make it a lot faster as well. You don't need -E
here, you could even do with -F:

find /src/dir -type f -exec \
grep -F -e alter -e modify -e replace /dev/null {} +

--
Stéphane

Re: grep doubt

am 24.04.2008 17:44:40 von Stephane CHAZELAS

2008-04-24, 17:36(+02), pk:
> On Thursday 24 April 2008 16:32, mallin.shetland wrote:
>
>> apogeusistemas@gmail.com scrisse:
>>
>>> I need find all occurences of alter, modify and replace in all files,
>>> how could I make this ?
>>
>> grep -R -e alter -e modify -e replace *
>
> Depending on your shell, this may not catch hidden files and directories at
> the first level.
> Also, using -F /might/ be more efficient.

A problem with most versions of grep that support the -R
non-standard option is that it follows the symlinks (as if
-follow was given to find).

To avoid the problem with hidden files (or files whose name
starts with "-" or if there are too many files for the E2BIG
execve(2) limit), simply do:

grep -FR -e alter -e modify -e replace .

--
Stéphane

Re: grep doubt

am 24.04.2008 17:47:23 von apogeusistemas

On Apr 24, 12:44=A0pm, Stephane CHAZELAS
wrote:
> 2008-04-24, 17:36(+02), pk:
>
> > On Thursday 24 April 2008 16:32, mallin.shetland wrote:
>
> >> apogeusiste...@gmail.com scrisse:
>
> >>> I need find all occurences of alter, modify and replace in all files,
> >>> how could I make this ?
>
> >> grep -R -e alter -e modify -e replace *
>
> > Depending on your shell, this may not catch hidden files and directories=
at
> > the first level.
> > Also, using -F /might/ be more efficient.
>
> A problem with most versions of grep that support the -R
> non-standard option is that it follows the symlinks (as if
> -follow was given to find).
>
> To avoid the problem with hidden files (or files whose name
> starts with "-" or if there are too many files for the E2BIG
> execve(2) limit), simply do:
>
> grep -FR -e alter -e modify -e replace .
>
> --
> St=E9phane

Thank You so much for your informations !!!

Re: grep doubt

am 24.04.2008 17:55:36 von PK

On Thursday 24 April 2008 17:44, Stephane CHAZELAS wrote:

> A problem with most versions of grep that support the -R
> non-standard option is that it follows the symlinks (as if
> -follow was given to find).

(do you mean -L?)

I understand that this may yield different results between

find . ... | xargs grep

and

grep -R .

....but isn't following the symlinks the only sensible behavior for grep?
Or maybe I did not understand what you mean.

--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.

Re: grep doubt

am 24.04.2008 18:11:32 von Chris Mattern

On 2008-04-24, apogeusistemas@gmail.com wrote:
>
> Hi:
>
> Can you tell me why when I run this script I only get this output ?
>
> solaris> cat script1
>
> for file in `ls -R`
> do
> grep -iw alter $file > /apl/applprox/script1_output
> grep -iw modify $file >> /apl/applprox/script1_output
> grep -iw replace $file >> /apl/applprox/script1_output
> done
>
>
>
> grep: can't open OEXWFOIB.pls
> grep: can't open OEXWFOIB.pls
> grep: can't open OEXWFOIS.pls
> grep: can't open OEXWFOIS.pls
> grep: can't open OEXWFOIS.pls
> grep: can't open OEXXHDRB.pls
> grep: can't open OEXXHDRB.pls
> grep: can't open OEXXHDRB.pls
> grep: can't open OEXXHDRS.pls
> grep: can't open OEXXHDRS.pls
> grep: can't open OEXXHDRS.pls
> grep: can't open OEXXLINB.pls
> grep: can't open OEXXLINB.pls

Offhand, I'd say you can't open those files. Do you have
read permission for them?


--
Christopher Mattern

NOTICE
Thank you for noticing this new notice
Your noticing it has been noted
And will be reported to the authorities

Re: grep doubt

am 24.04.2008 18:22:59 von Stephane CHAZELAS

2008-04-24, 17:55(+02), pk:
> On Thursday 24 April 2008 17:44, Stephane CHAZELAS wrote:
>
>> A problem with most versions of grep that support the -R
>> non-standard option is that it follows the symlinks (as if
>> -follow was given to find).
>
> (do you mean -L?)

Yes well, -L is the "more standard" version for the "more
portable" -follow.

> I understand that this may yield different results between
>
> find . ... | xargs grep
>
> and
>
> grep -R .
>
> ...but isn't following the symlinks the only sensible behavior for grep?
> Or maybe I did not understand what you mean.

Well, while it may be what you want in some cases, it generally
isn't, as when you do "grep pattern directory", you want do
know if "pattern" is in any file in that directory tree, and not
in any other directory tree linked to it, especially when you
consider that all the other commands that do recurse into
subdirectories (ls, find, zsh's **/, chown, chgrp, chmod...) do
not by default (exception for chown/chgrp on some systems).

That means you may endup looking at the same files twice or
more, also consider the case of a symlink to "/" for instance.
At least, grep should have an option for disabling it.

--
Stéphane

Re: grep doubt

am 24.04.2008 18:40:59 von PK

On Thursday 24 April 2008 18:22, Stephane CHAZELAS wrote:

>> ...but isn't following the symlinks the only sensible behavior for grep?
>> Or maybe I did not understand what you mean.
>
> Well, while it may be what you want in some cases, it generally
> isn't, as when you do "grep pattern directory", you want do
> know if "pattern" is in any file in that directory tree, and not
> in any other directory tree linked to it, especially when you
> consider that all the other commands that do recurse into
> subdirectories (ls, find, zsh's **/, chown, chgrp, chmod...) do
> not by default (exception for chown/chgrp on some systems).
>
> That means you may endup looking at the same files twice or
> more, also consider the case of a symlink to "/" for instance.
> At least, grep should have an option for disabling it.

Ah ok. While the programs you mention act upon file metadata, and thus not
following links make sense, grep acts upon file content, so to me it seemed
kind of pointless for grep to look for the pattern inside the link (which
contains just the pointed-to filename). If such an option existed, it would
better make grep ignore symlinks altogether, rather than trying to read
them, imho.

--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.

Re: grep doubt

am 24.04.2008 18:47:08 von apogeusistemas

On Apr 24, 1:40=A0pm, pk wrote:
> On Thursday 24 April 2008 18:22, Stephane CHAZELAS wrote:
>
> >> ...but isn't following the symlinks the only sensible behavior for grep=
?
> >> Or maybe I did not understand what you mean.
>
> > Well, while it may be what you want in some cases, it generally
> > isn't, as when you do "grep pattern directory", you want do
> > know if "pattern" is in any file in that directory tree, and not
> > in any other directory tree linked to it, especially when you
> > consider that all the other commands that do recurse into
> > subdirectories (ls, find, zsh's **/, chown, chgrp, chmod...) do
> > not by default (exception for chown/chgrp on some systems).
>
> > That means you may endup looking at the same files twice or
> > more, also consider the case of a symlink to "/" for instance.
> > At least, grep should have an option for disabling it.
>
> Ah ok. While the programs you mention act upon file metadata, and thus not=

> following links make sense, grep acts upon file content, so to me it seeme=
d
> kind of pointless for grep to look for the pattern inside the link (which
> contains just the pointed-to filename). If such an option existed, it woul=
d
> better make grep ignore symlinks altogether, rather than trying to read
> them, imho.
>
> --
> All the commands are tested with bash and GNU tools, so they may use
> nonstandard features. I try to mention when something is nonstandard (if
> I'm aware of that), but I may miss something. Corrections are welcome.

I made this script and now it works fine...

for file in `find . -type f`
do
grep -w ALTER $file >> /apl/applprox/script1_output
grep -w MODIFY $file >> /apl/applprox/script1_output
grep -w REPLACE $file >> /apl/applprox/script1_output
done

Thank you...

Re: grep doubt

am 24.04.2008 21:37:19 von OldSchool

On Apr 24, 9:25=A0am, apogeusiste...@gmail.com wrote:

> for file in `ls -R`
> do
> grep -iw alter $file > /apl/applprox/script1_output
> grep -iw modify $file >> /apl/applprox/script1_output
> grep -iw replace $file >> /apl/applprox/script1_output
> done
>
> grep: can't open OEXWFOIB.pls
> grep: can't open OEXWFOIB.pls
> grep: can't open OEXXLINB.pls

one of the potential issues w/ the "ls -R" construct is that while you
get at list of files in sub-directories, you don't know where the
are. The grep is looking for them in the current working directory
only regardless of where they really are