Word Search: Can you please check if this is correct. thanks!

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Word Search: Can you please check if this is correct. thanks!
# 1  
Old 03-07-2011
Power Word Search: Can you please check if this is correct. thanks!

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:
Im currently doing a search command.. for example , when i typed a certain word , lets say "DOG".. all directories,files,script and any other files that contain the word "DOG" will be displayed in the screen.. i used PICO , as the script editor. thank you guys!



2. Relevant commands, code, scripts, algorithms:
FIND



3. The attempts at a solution (include all code and scripts):
i made two attempts:
ATTEMPT 1:

Echo enter word to search :
read word
find -name $word

ATTEMPT 2:
Echo enter word to search:
read word
find / -name $word 2>/dev/null



4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

SAINT LOUIS UNIVERSITY , BAGUIO CITY , PHILIPPINES, MAM SUSAN CASTILLO, OPERATING SYSTEM IT222.

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
# 2  
Old 03-08-2011
Quote:
Originally Posted by jenimesh19
ATTEMPT 1:
echo enter word to search :
read word
find -name $word
This will not work as you didn't provide the path on which the find command willl look for the word (but you probably found this yourself as you propose another solution)

Quote:
Originally Posted by jenimesh19
ATTEMPT 2:
echo enter word to search:
read word
find / -name $word 2>/dev/null
This will be better but you will only find the files and directories whose names are exactly $word (case sensitive).
This User Gave Thanks to Dahu For This Post:
# 3  
Old 03-08-2011
So i must put there [Aa-Zz]?SmilieSmilie
# 4  
Old 03-08-2011
you can use wild-cards such as asterix(*) in your name field so long as you escape them (or single quote them)
This User Gave Thanks to Skrynesaver For This Post:
# 5  
Old 03-08-2011
Power

[code]
echo " PLEASE ENTER WORD TO SEARCH:"
read 'word' # LIKE THIS?

find -name $word
echo
echo
find /-name $word 2>/dev/null

---------- Post updated at 05:00 AM ---------- Previous update was at 04:59 AM ----------

i put single quote on the word

Code:
echo " PLEASE ENTER WORD TO SEARCH:"
read 'word'   # LIKE THIS? 

find -name $word
echo
echo
find /-name $word 2>/dev/null



THANKS!!!
# 6  
Old 03-08-2011
As somebody suggested on your duplicate post, it's time to read about the "grep" command.

Code:
# To find all file or directory names which contain the value of $word
echo " PLEASE ENTER WORD TO SEARCH:"
read word
# Case insignificant grep (the -i switch)
find . -print | grep -i "${word}"

Before we go any further, please post what Operating System and Shell you have:
Code:
uname -a
echo $SHELL

# 7  
Old 03-09-2011
More like this ... it's the argument of find that should be quoted
Code:
echo " PLEASE ENTER WORD TO SEARCH:"
read word
find /-name "*${word}*" 2>/dev/null

Beware, this search is case-sensitive. If you need an case-insensitive search use -iname instead of -name
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to search for a word in column header that fully matches the word not partially in awk?

I have a multicolumn text file with header in the first row like this The headers are stored in an array called . which contains I want to search for each elements of this array from that multicolumn text file. And I am using this awk approach for ii in ${hdr} do gawk -vcol="$ii" -F... (1 Reply)
Discussion started by: Atta
1 Replies

2. UNIX for Beginners Questions & Answers

UNIX script to check word count of each word in file

I am trying to figure out to find word count of each word from my file sample file hi how are you hi are you ok sample out put hi 1 how 1 are 1 you 1 hi 1 are 1 you 1 ok 1 wc -l filename is not helping , i think we will have to split the lines and count and then print and also... (4 Replies)
Discussion started by: mirwasim
4 Replies

3. Shell Programming and Scripting

Search for a specific word and print only the word from the input file

Hi, I have a sample file as shown below, I am looking for sed or any command which prints the complete word only from the input file. Ex: $ cat "sample.log" I am searching for a word which is present in this file We can do a pattern search using grep but I need to cut only the word which... (1 Reply)
Discussion started by: mohan_kumarcs
1 Replies

4. Shell Programming and Scripting

Search for the word and exporting 35 characters after that word using shell script

I have a file input.txt which have loads of weird characters, html tags and useful materials. I want to display 35 characters after the word "description" excluding weird characters like $&lmp and without html tags in the new file output.txt. Help me. Thanx in advance. I have attached the input... (4 Replies)
Discussion started by: sachit adhikari
4 Replies

5. Shell Programming and Scripting

Search for the word and exporting 35 characters after that word using shell script?

I have a file input.txt which have loads of weird characters, html tags and useful materials. I want to display 35 characters after the word description excluding weird characters like $$#$#@$#@***$# and without html tags in the new file output.txt. Help me. Thanx in advance. My final goal is to... (11 Replies)
Discussion started by: sachit adhikari
11 Replies

6. UNIX for Dummies Questions & Answers

Script to search for a particular word in files and print the word and path name

Hi, i am new to unix shell scripting and i need a script which would search for a particular word in all the files present in a directory. The output should have the word and file path name. For example: "word" "path name". Thanks for the reply in adv,:) (3 Replies)
Discussion started by: virtual_45
3 Replies

7. Shell Programming and Scripting

Search the word to be deleted and delete lines above this word starting from P1 to P3

Hi, I have to search a word in a text file and then I have to delete lines above from the word searched . For eg suppose the file is like this: Records P1 10,23423432 ,77:1 ,234:2 P2 10,9089004 ,77:1 ,234:2 ,87:123 ,9898:2 P3 456456 P1 :123,456456546 P2 abc:324234 (2 Replies)
Discussion started by: vsachan
2 Replies

8. Shell Programming and Scripting

WORD SEARCH - CHECK IF CORRECT!

Im currently working on a Script using PICO editor, the scripts purpose is : When you typed a certain "word" and press enter, All directories, Script, and any other files that contain that "word" will be displayed.. for example i typed "DOG".. all executable script, Directories, and any other... (3 Replies)
Discussion started by: jenimesh19
3 Replies

9. Shell Programming and Scripting

perl (word by word check if a hash key)

Hi, Now i work in a code that 1-get data stored in the database in the form of hash table with a key field which is the " Name" 2-in the same time i open a txt file and loop through it word by word 3- which i have a problem in is that : I need to loop word by word and check if it is a... (0 Replies)
Discussion started by: eng_shimaa
0 Replies

10. Shell Programming and Scripting

How to check a string conating a search word or not ...

Hi fiends, I need some help. i have a var called fname="req_detail_TAM.dat" and is have a search string var as tmp="TAM". Now my requirement is i need to check whether a "fname" is contains "search str" or not. if search string is part of the filename, then i need to store value 1 in a... (2 Replies)
Discussion started by: manu.vmr
2 Replies
Login or Register to Ask a Question