Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > alt.os.linux.debian > #8416 > unrolled thread

Simple script fools me?

Started bydog@gmail.com
First post2016-09-29 11:57 +0000
Last post2016-10-04 17:50 +0000
Articles 6 — 4 participants

Back to article view | Back to alt.os.linux.debian


Contents

  Simple script fools me? dog@gmail.com - 2016-09-29 11:57 +0000
    Re: Simple script fools me? William Unruh <unruh@invalid.ca> - 2016-09-29 14:04 +0000
      Re: Simple script fools me? Dan Purgert <dan@djph.net> - 2016-09-29 14:18 +0000
        Re: Simple script fools me? William Unruh <unruh@invalid.ca> - 2016-09-29 15:45 +0000
          Re: Simple script fools me? Dan Purgert <dan@djph.net> - 2016-09-29 18:16 +0000
    Re: Simple script fools me? Ivan Shmakov <ivan@siamics.net> - 2016-10-04 17:50 +0000

#8416 — Simple script fools me?

Fromdog@gmail.com
Date2016-09-29 11:57 +0000
SubjectSimple script fools me?
Message-ID<nsivjc$ckm$1@dont-email.me>
Simple script fools me?

#!/bin/bash
echo -n " find files here containing PHRASE: "
echo $1
    find . -type f | \
    grep -v pdf  | \
    grep -v wav  | \
    grep -v mp3  | \
    xargs  grep -l "$1" | grep -v grep
exit.

I want to avoid the output-lines:-
...
grep: ./JS/Documents/Scratch: No such file or directory
grep: Projects/Circle30.sb: No such file or directory
grep: ./JS/Documents/Scratch: No such file or directory
grep: Projects/ZeroOne.sb: No such file or directory

Not only what-to-use, but why mine-fails.

[toc] | [next] | [standalone]


#8417

FromWilliam Unruh <unruh@invalid.ca>
Date2016-09-29 14:04 +0000
Message-ID<nsj70m$4vp$1@dont-email.me>
In reply to#8416
On 2016-09-29, dog@gmail.com <dog@gmail.com> wrote:
> Simple script fools me?
>
> #!/bin/bash
> echo -n " find files here containing PHRASE: "
> echo $1
>     find . -type f | \
>     grep -v pdf  | \
>     grep -v wav  | \
>     grep -v mp3  | \
>     xargs  grep -l "$1" | grep -v grep
> exit.

Uh, why not just
grep -r -l "$1" .
instead of all those grep phrases? 
YOu could then filter out all those files you do not want.

grep -r -l "$1" 2>/dev/null |egrep -v 'pdf$|wav$|mp3$'
>
> I want to avoid the output-lines:-
> ...
> grep: ./JS/Documents/Scratch: No such file or directory
> grep: Projects/Circle30.sb: No such file or directory
> grep: ./JS/Documents/Scratch: No such file or directory
> grep: Projects/ZeroOne.sb: No such file or directory
>
> Not only what-to-use, but why mine-fails.

Those are grep errors put out on stderr (which by default is directed to
the console, as well as stdout).

>

[toc] | [prev] | [next] | [standalone]


#8418

FromDan Purgert <dan@djph.net>
Date2016-09-29 14:18 +0000
Message-ID<slrnnuq8ja.78j.dan@xps-linux.djph.net>
In reply to#8417
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

William Unruh wrote:
> On 2016-09-29, dog@gmail.com <dog@gmail.com> wrote:
>> Simple script fools me?
>>
>> #!/bin/bash
>> echo -n " find files here containing PHRASE: "
>> echo $1
>>     find . -type f | \
>>     grep -v pdf  | \
>>     grep -v wav  | \
>>     grep -v mp3  | \
>>     xargs  grep -l "$1" | grep -v grep
>> exit.
>
> Uh, why not just
> grep -r -l "$1" .
> instead of all those grep phrases? 
> YOu could then filter out all those files you do not want.
>
> grep -r -l "$1" 2>/dev/null |egrep -v 'pdf$|wav$|mp3$'

or, 
find . -type f -name "$1" (or *$1*) | egrep -v 'pdf|wav|mp3'

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQEcBAEBAgAGBQJX7SJpAAoJEI4R3fMSeaKBpoQH/1xtKlg/xgXlSAF+PEmjRYYn
a+7rb6p22olCn35x5V1IFZvZSWNpnYnDBRPDdNNNdmGqxMtvbcB6epkwBIColnET
JduwZsW6DUy5DTXRg75fGSGLZ5yTUFL5aZPhD2HuDIBI3xSwTiTuljQj/xSEME59
lhiLEEN4Fktj1xth8BlDbZ5AFZPnXb2dCDbTB8vyjxZ9WW5XvYRQJ7HgvPlYp5od
PiJwnR8qrXFnrzckg238ZmU7UVnLj1X/rwVcxeb6/PC4Bp5lGcMKNGfHJA2GKRsB
phVS72qvBxwn0OZjXB6ZPEwRtR3nuEoYkEZxNtw2aQE7VuoyDWK0XWW8+p8eHEY=
=CXC8
-----END PGP SIGNATURE-----

-- 
|_|O|_| Registered Linux user #585947
|_|_|O| Github: https://github.com/dpurgert
|O|O|O| PGP: 05CA 9A50 3F2E 1335 4DC5  4AEE 8E11 DDF3 1279 A281

[toc] | [prev] | [next] | [standalone]


#8419

FromWilliam Unruh <unruh@invalid.ca>
Date2016-09-29 15:45 +0000
Message-ID<nsjcun$sj3$1@dont-email.me>
In reply to#8418
On 2016-09-29, Dan Purgert <dan@djph.net> wrote:
>
> William Unruh wrote:
>> On 2016-09-29, dog@gmail.com <dog@gmail.com> wrote:
>>> Simple script fools me?
>>>
>>> #!/bin/bash
>>> echo -n " find files here containing PHRASE: "
>>> echo $1
>>>     find . -type f | \
>>>     grep -v pdf  | \
>>>     grep -v wav  | \
>>>     grep -v mp3  | \
>>>     xargs  grep -l "$1" | grep -v grep
>>> exit.
>>
>> Uh, why not just
>> grep -r -l "$1" .
>> instead of all those grep phrases? 
>> YOu could then filter out all those files you do not want.
>>
>> grep -r -l "$1" 2>/dev/null |egrep -v 'pdf$|wav$|mp3$'
>
> or, 
> find . -type f -name "$1" (or *$1*) | egrep -v 'pdf|wav|mp3'

That will throw away files called tidalwave.txt which the user might
want to actually save-- you want the pdf, wav, mp3 to be at the end of
the filename I assume.
Also, in his script,  $1 was  in  the content of the file not the name of the file. 
>
>

[toc] | [prev] | [next] | [standalone]


#8420

FromDan Purgert <dan@djph.net>
Date2016-09-29 18:16 +0000
Message-ID<slrnnuqmgo.78j.dan@xps-linux.djph.net>
In reply to#8419
William Unruh wrote:
> On 2016-09-29, Dan Purgert <dan@djph.net> wrote:
>>
>> William Unruh wrote:
>>> On 2016-09-29, dog@gmail.com <dog@gmail.com> wrote:
>>>> Simple script fools me?
>>>>
>>>> #!/bin/bash
>>>> echo -n " find files here containing PHRASE: "
>>>> echo $1
>>>>     find . -type f | \
>>>>     grep -v pdf  | \
>>>>     grep -v wav  | \
>>>>     grep -v mp3  | \
>>>>     xargs  grep -l "$1" | grep -v grep
>>>> exit.
>>>
>>> Uh, why not just
>>> grep -r -l "$1" .
>>> instead of all those grep phrases? 
>>> YOu could then filter out all those files you do not want.
>>>
>>> grep -r -l "$1" 2>/dev/null |egrep -v 'pdf$|wav$|mp3$'
>>
>> or, 
>> find . -type f -name "$1" (or *$1*) | egrep -v 'pdf|wav|mp3'
>
> That will throw away files called tidalwave.txt which the user might
> want to actually save-- you want the pdf, wav, mp3 to be at the end of
> the filename I assume.
> Also, in his script,  $1 was  in  the content of the file not the name
> of the file.


*sigh* been a long day, and it's barely even half over ... 

-- 
|_|O|_| Registered Linux user #585947
|_|_|O| Github: https://github.com/dpurgert
|O|O|O| PGP: 05CA 9A50 3F2E 1335 4DC5  4AEE 8E11 DDF3 1279 A281

[toc] | [prev] | [next] | [standalone]


#8431

FromIvan Shmakov <ivan@siamics.net>
Date2016-10-04 17:50 +0000
Message-ID<87mvikxaue.fsf@violet.siamics.net>
In reply to#8416
>>>>> dog@gmail.com writes:

	[Cross-posting to comp.unix.shell as I see nothing
	Debian-specific here.]

 > Simple script fools me?

 > #!/bin/bash
 > echo -n " find files here containing PHRASE: "
 > echo $1
 >     find . -type f | \
 >     grep -v pdf  | \
 >     grep -v wav  | \
 >     grep -v mp3  | \
 >     xargs  grep -l "$1" | grep -v grep
 > exit.

 > I want to avoid the output-lines:

 > grep: ./JS/Documents/Scratch: No such file or directory
 > grep: Projects/Circle30.sb: No such file or directory
 > grep: ./JS/Documents/Scratch: No such file or directory
 > grep: Projects/ZeroOne.sb: No such file or directory

find . -type f \
    -not -name \*pdf\* \
    -not -name \*wav\* \
    -not -name \*mp3\* \
    -exec grep -l -- "$1" {} + 

	Somehow, I assume that the 'grep -v grep' part was left from a
	'ps ax | grep something' command, so I've omitted it here.

 > Not only what-to-use, but why mine-fails.

	Because of whitespace.

	Suppose that find(1) gives us these filenames:

To sleep: perchance to dream: ay, there's the rub.wav
For in that sleep of death what dreams may come.pdf
When we have shuffled off this mortal coil.mp3
Must give us pause: there's the respect.jpeg
That makes calamity of so long life.text

	After the three-grep(1) sequence, what remains is:

Must give us pause: there's the respect.jpeg
That makes calamity of so long life.text

	As long as xargs(1) is concerned, these two lines contain the
	following four parameters to be passed to the 'grep -l "$1"'
	command:

Must
give
us
pause:

	And just after these four, xargs(1) stumbles upon an unmatched
	single quote in "there's", but that's beside the point.

	The usual solution is to put as much logic into the find(1)
	command, and use '-exec COMMAND ARGUMENTS... -- {} +' at the end
	of said find(1) invocation.  Alternatively, it's possible to use
	find -print0, grep -z, and xargs -r0, in which case only the
	ASCII "NUL" control code (never possible in Unix filenames) will
	be treated as separator.

	It's of course possible to do even more complex stuff with
	find(1).  Consider, e. g.:

$ find    \( -type f -name \*.pdf  -exec pdfsearch  -- foo {} + \) \
      -or \( -type f -name \*.jpeg -exec exifsearch -- bar {} + \) 

-- 
FSF associate member #7257  58F8 0F47 53F5 2EB2 F6A5  8916 3013 B6A0 230E 334A

[toc] | [prev] | [standalone]


Back to top | Article view | alt.os.linux.debian


csiph-web