Re: [SLUG] A command question.

2008-11-21 Thread Amos Shapira
2008/11/21 Jobst Schmalenbach [EMAIL PROTECTED]:

 Hi.

 I beg to differ.

  1: its quicker to type fstr HTML '*.php'

It's shorter to define:

function fstr() { grep -r --colour=always --include=${2:-*} $1 . | less -R; }

If you insist on using fstr :)


  2: less (and more) kill the highlighting done by grep

I said, Jeff repeated and I'll repeat it again - less -R doesn't kill colors.

  3: grep has to (internally) call the other processes to to the same I am 
 already doing with pipes

Nope. Grep doesn't have to call 4 external programs (find, xrgs, grep
and sed) to find files, open them, search for a string and
color-hilight it.
I didn't even count the couple of calls to tput.

Do a little experiment - time(1) the two options (run each at least
twice so the other option won't benefit from caching offered by the
first run).


  4: (overly pedantic): can do more with find grep can ever do and I can 
 decide the order of my pipes and WHAT I want to do.

But not with fstr() as you defined it above.

If you insist on using find(1)'s file picking power then even the
following looks a bit more appealing to me:

function fstr() { find ${2} -print0 | grep --colour=always $1 | less -R }

(BTW - I already benefited from this thread - I just noticed grep's
--exclude-dir which will allow me to exclude .svn directories even
better - thanks!).

Plus if you get used to using grep -r etc then it's more readily
available on foreign territory (e.g. one of the dozens of servers we
manage on which I didn't get around to install all my favorite
aliases).

Cheers,

--Amos
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] A command question.

2008-11-20 Thread Jobst Schmalenbach

Hi.

I beg to differ.

 1: its quicker to type fstr HTML '*.php'

 2: less (and more) kill the highlighting done by grep

 3: grep has to (internally) call the other processes to to the same I am 
already doing with pipes

 4: (overly pedantic): can do more with find grep can ever do and I can decide 
the order of my pipes and WHAT I want to do.


Jobst




On Mon, Nov 17, 2008 at 03:49:22PM +1100, Amos Shapira ([EMAIL PROTECTED]) 
wrote:
 2008/11/17 Jobst Schmalenbach [EMAIL PROTECTED]:
 
  Put this into your .bashrc file:
 
  function fstr()
  {
 OPTIND=1
 local case= 
 local usage=fstr: find string in files.\nUsage: fstr [-i] \pattern\ 
  [\filename pattern\] 
 while getopts :it opt
 ...
   find . -type f -name ${2:-*} -print0 | xargs -0 grep -sn ${case} $1 
  2- | sed s/$1/${SMSO}\0${RMSO}/gI | more
 
 It's a nice excercise in bash scripting but quiet redundant with
 today's GNU grep:
 -R/-r/--recursive will replace the find
 --include=pattern will replace find's -name ... (though many times I
 use --exclude \*.svn-base to skip SVN files)
 --colour will highlight the results
 
 Less' -R/--RAW-CONTROl-CHARS will help page through the highlighted output.
 
 So in the end you can achieve the same result with something like:
 
 grep -r --colour pattern directory/ | less -R
 
 --Amos
 -- 
 SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
 Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

-- 
Never share a foxhole with anyone braver than yourself.

  | |0| |   Jobst Schmalenbach, [EMAIL PROTECTED], General Manager
  | | |0|   Barrett Consulting Group P/L  The Meditation Room P/L
  |0|0|0|   +61 3 9532 7677, POBox 277, Caulfield South, 3162, Australia
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] A command question.

2008-11-20 Thread Jeff Waugh
quote who=Jobst Schmalenbach

  2: less (and more) kill the highlighting done by grep

Use less -R and *never* use more!

  3: grep has to (internally) call the other processes to to the same I am
  already doing with pipes

No, there's a massive difference between syscalls and forking processes.

  4: (overly pedantic): can do more with find grep can ever do and I can
  decide the order of my pipes and WHAT I want to do.

In some cases, yes. But most search recursively for files that contain X
use cases are better served by the vastly more performant grep -r.

- Jeff

-- 
Robot Parade  http://www.robotparade.com.au/
 
  m. +61 423 989 818 p. +61 2 9318 0284 f. +61 2 9318 2884
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] A command question.

2008-11-16 Thread Jobst Schmalenbach

Put this into your .bashrc file:

function fstr()
{ 
OPTIND=1
local case= 
local usage=fstr: find string in files.\nUsage: fstr [-i] \pattern\ 
[\filename pattern\] 
while getopts :it opt
do
case $opt in
i) case=-i  ;;
*) echo $usage; return;;
esac
done
shift $(( $OPTIND - 1 ))
if [ $# -lt 1 ]; then
echo $usage
return;
fi
local SMSO=$(tput smso)
local RMSO=$(tput rmso)
find . -type f -name ${2:-*} -print0 | xargs -0 grep -sn ${case} $1 
2- | sed s/$1/${SMSO}\0${RMSO}/gI | more
}

... comes with the lot, even highlighting.

;-)


Jobst













On Fri, Nov 14, 2008 at 07:14:22PM +1100, [EMAIL PROTECTED] ([EMAIL PROTECTED]) 
wrote:
 Is there a command that finds a file containing a certain word?
 
 find and apropos don't. They work on filenames only.
 
 Using Hardy H.
 
 Any suggestions gratefully etc.
 
 Bill Bennett
 -- 
 SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
 Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

-- 
When you lose, don't lose the lesson.

  | |0| |   Jobst Schmalenbach, [EMAIL PROTECTED], General Manager
  | | |0|   Barrett Consulting Group P/L  The Meditation Room P/L
  |0|0|0|   +61 3 9532 7677, POBox 277, Caulfield South, 3162, Australia
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] A command question.

2008-11-16 Thread Amos Shapira
2008/11/17 Jobst Schmalenbach [EMAIL PROTECTED]:

 Put this into your .bashrc file:

 function fstr()
 {
OPTIND=1
local case= 
local usage=fstr: find string in files.\nUsage: fstr [-i] \pattern\ 
 [\filename pattern\] 
while getopts :it opt
...
  find . -type f -name ${2:-*} -print0 | xargs -0 grep -sn ${case} $1 2- 
 | sed s/$1/${SMSO}\0${RMSO}/gI | more

It's a nice excercise in bash scripting but quiet redundant with
today's GNU grep:
-R/-r/--recursive will replace the find
--include=pattern will replace find's -name ... (though many times I
use --exclude \*.svn-base to skip SVN files)
--colour will highlight the results

Less' -R/--RAW-CONTROl-CHARS will help page through the highlighted output.

So in the end you can achieve the same result with something like:

grep -r --colour pattern directory/ | less -R

--Amos
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


[SLUG] A command question.

2008-11-14 Thread wbennett
Is there a command that finds a file containing a certain word?

find and apropos don't. They work on filenames only.

Using Hardy H.

Any suggestions gratefully etc.

Bill Bennett
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] A command question.

2008-11-14 Thread Jeff Waugh
quote who=[EMAIL PROTECTED]

 Is there a command that finds a file containing a certain word?
 
 find and apropos don't. They work on filenames only.

grep ... and you can use -r to search through files/directories recursively.

- Jeff

-- 
Robot Parade  http://www.robotparade.com.au/
 
  m. +61 423 989 818 p. +61 2 9318 0284 f. +61 2 9318 2884
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] A command question.

2008-11-14 Thread Rick Welykochy

Jeff Waugh wrote:


quote who=[EMAIL PROTECTED]


Is there a command that finds a file containing a certain word?

find and apropos don't. They work on filenames only.


grep ... and you can use -r to search through files/directories recursively.


You can also use -i to do a case insensitive search.
And there are dozens of other flags to confuse you!

man grep === tells all.

And to add to the mix, there are variants fgrep and egrep :)

cheers
rickw


--
_
Rick Welykochy || Praxis Services

Tis the dream of each programmer before his life is done,
To write three lines of APL and make the damn thing run.
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] A command question.

2008-11-14 Thread Mada R Perdhana
find . -exec grep www.athabasca '{}' \; -print

 This command will search in the current directory and all sub directories.
All files that contain the string will have their path printed to standard
output.

If you want to just find each file then pass it on for processing use the -q
grep option. This finds the first occurrance of the search string. It then
signals success to find and find continues searching for more files.

find . -exec grep -q www.athabasca '{}' \; -print

 This command is very important for process a series of files that contain a
specific string. You can then process each file appropriately. An example is
find all html files with the string www.athabascau.ca. You can then
process the files with a sed script to change those occurrances of 
www.athabascau.ca with intra.athabascau.ca.


On Fri, Nov 14, 2008 at 3:14 PM, [EMAIL PROTECTED] wrote:

 Is there a command that finds a file containing a certain word?

 find and apropos don't. They work on filenames only.

 Using Hardy H.

 Any suggestions gratefully etc.

 Bill Bennett
 --
 SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
 Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html




-- 
Never Trust an Operating System You don't have the Source for...
Closed Source for device Driver are ILLEGAL and not Ethical... act!
Isn't it, MS Windows a real multitasking OS?, Why? 'Cause It can boot and
crash simultaneously!
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] A command question.

2008-11-14 Thread Jeff Waugh
quote who=Mada R Perdhana

 find . -exec grep www.athabasca '{}' \; -print

This is massively inefficient. A better choice would be grep -rl piped to
xargs.

grep -rl www.athabasca | xargs sed -i 's#www.athabasca#www.bathsheba#'

- Jeff

-- 
OSDC 2008: Sydney, Australiahttp://www.osdc.com.au/2008/
 
It will test your head. And your mind. And your brain, too. - Jack
   Black, School of Rock
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] A command question.

2008-11-14 Thread Ben Nisenbaum

[EMAIL PROTECTED] wrote:

Is there a command that finds a file containing a certain word?

find and apropos don't. They work on filenames only.

Using Hardy H.

Any suggestions gratefully etc.

Bill Bennett


Hello Bill,

find . -name * -print -exec grep word {} \;

finds the word word in files in the current directory
on my system, and prints the relevant file name.

Ben
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html