LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-20-2006, 01:05 PM   #1
prospekrisal
LQ Newbie
 
Registered: May 2006
Location: Kuching, Malaysia
Posts: 26

Rep: Reputation: 15
search file contains word


how to differ whether the file contains a word or not in shell script?
is there any simple command?
 
Old 07-20-2006, 01:24 PM   #2
burninGpi
Member
 
Registered: Mar 2006
Location: Fort McMurray, Canada
Distribution: Gentoo ~amd64
Posts: 163

Rep: Reputation: 30
Use grep. simple sysntax:
Code:
grep <word> <file>
see man 1 grep for details.
 
Old 07-20-2006, 03:46 PM   #3
csmarkus
LQ Newbie
 
Registered: Jun 2006
Location: Budapest, Hungary
Distribution: Debian
Posts: 4

Rep: Reputation: 0
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> .
 
Old 07-20-2006, 08:12 PM   #4
prospekrisal
LQ Newbie
 
Registered: May 2006
Location: Kuching, Malaysia
Posts: 26

Original Poster
Rep: Reputation: 15
Im not following u guys. Why should I type the word? cud u gimme the example instead of syntax?
 
Old 07-20-2006, 08:30 PM   #5
burninGpi
Member
 
Registered: Mar 2006
Location: Fort McMurray, Canada
Distribution: Gentoo ~amd64
Posts: 163

Rep: Reputation: 30
as an example, to see if "hello.txt" contains "bob", you would type:
Code:
grep bob hello.txt
 
Old 07-20-2006, 10:24 PM   #6
prospekrisal
LQ Newbie
 
Registered: May 2006
Location: Kuching, Malaysia
Posts: 26

Original Poster
Rep: Reputation: 15
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Word search Alien_Hominid Slackware 5 04-19-2006 06:52 AM
search a file for a word - bash script paul_mat Linux - Software 12 04-16-2006 02:59 AM
I have a harddrive that I want to search for deleted word files, what do I do first? abefroman Linux - Security 2 07-31-2005 08:37 PM
remove color after word search in vi editor dylan912 Linux - Newbie 1 12-10-2004 05:15 AM
How do i change the word "FISH" when i use Lan search ? frank-01 Linux - Networking 11 01-22-2004 04:00 PM


All times are GMT -5. The time now is 10:29 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration