search file contains word
how to differ whether the file contains a word or not in shell script?
is there any simple command? |
Use grep. simple sysntax:
Code:
grep <word> <file> |
Yes, grep is your friend. And should you be looking for which files contain the word (non case sensitive) in and below the current directory, use
Code:
grep -ri <word> . |
Im not following u guys. Why should I type the word? cud u gimme the example instead of syntax?
|
as an example, to see if "hello.txt" contains "bob", you would type:
Code:
grep bob hello.txt |
i've done that command in shell script
if grep for file then echo "The file contains the word" else echo "The file doesn't contain the word" fi output fahrisal@linux:~> sh wordscript for FILE in $* The file contains the word then I was asked by my mentor "to modify whether a parameter was passed before commencing the greppin process." wht does it mean? i dont get it. |
All times are GMT -5. The time now is 06:28 AM. |