how to search word in group of files using command
hi
i am using openSUSE 10.3 & like to use power of terminal to do tasks.I want to search all files containing word 'echo' in given folder.What should be command. |
Try the "grep" command. Go into the directory you mean via command line and do (//EDIT: example improved to avoid confusion):
Code:
$ grep "yoursearchpattern" * The grep command is very useful by the way if you want to view the output of a file and filter this output for a given word. Say you have a file called blah.conf and want to view its contents: Code:
$ cat blah.conf Code:
$ cat blah.conf |grep example -A |
you could do
find . | xargs grep -i pattern it will show all the files in the current folder that have the pattern whether it is in lowercase or uppercase. kind regards |
Quote:
Code:
$ grep (yoursearchpattern) * |
Quote:
Code:
$ grep /(yoursearchpattern/) * |
Quote:
Code:
grep -i pattern -r . Code:
grep -i pattern -rc . |
Quote:
Code:
$ grep \(yoursearchpattern\) * Code:
$ grep "(yoursearchpattern)" * |
Quote:
|
Quote:
-A |
Code:
ls | grep "pattern" |
Quote:
|
Quote:
Code:
find -type f | grep -iP "\.(gif|jpe?g|png)$" | while read path In any case, the parentheses need to be managed to keep them from being interpreted by the shell -- that was my earlier point. |
Quote:
Code:
ls -l | grep <pattern> |
WHAT I HAVE LEARNT
I noticed that if I write grep pattern * then it gives file with corresponding lines.Also I should enclose search parameter in single or double quotes if it contains space. |
You should also use quotes when the search pattern has any wildcards---and in a few other situations.
You should also read up on the difference between single and double quotes---I would start with the Bash Guide for Beginners---free at http://tldp.org |
All times are GMT -5. The time now is 08:10 PM. |