LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   find!! (https://www.linuxquestions.org/questions/linux-newbie-8/find-813257/)

mohamad 06-09-2010 11:00 PM

find!!
 
lets say i have a file with names and numbers... each name has a number associated to it.
ex:
mary 676887
mike 88888

i want to be able to find the number by tyoing in the name in the command line... this is what i did

echo "Enter name: "
read name;
find . -iname '$name';
find . -iname '$no';
echo $name " " $no;;


what happens is that its just typing in what i write!!!

any ideas?!

pixellany 06-09-2010 11:10 PM

First, to use a variable in a statement, you typically have to put it in double-quotes, not single.

Second, where does the variable "no" get defined?

Third, the find command looks at filenames, and not content. To search for content, you need something like grep.

mohamad 06-09-2010 11:13 PM

grep
 
do i combine both find to find the file first and then grep to find the name i want from within the file?!!!
because i tried grep and i couldnt get the syntax right

chrism01 06-10-2010 01:02 AM

Example
Code:

grep name filename
returns the record matching the string 'name' in the file 'filename'. If you only want to see the number returned you could pipe that through awk http://www.grymoire.com/Unix/Awk.html.
There's some good bash tutorials eg http://rute.2038bug.com/index.html.gz

pixellany 06-10-2010 05:40 AM

The typical approach involves a loop which goes through a set of files and then calls grep for each filename. But first, make usre you are comfortable with the individual commands---show us an example of what you were trying with grep, and what the problem is.

"find" is used to find a file based on some attribute--including name, modification history, etc.

"grep" is used to find things inside one specific file.

Read the man pages for both of these and try things until you are comfortable with each command.

MTK358 06-10-2010 07:03 AM

Given the name, this will print the number:

Code:

echo -n 'Enter Name: '
read input
awk -v name="$input" '$1 == name { print $2 }' file-with-names


onebuck 06-10-2010 08:13 AM

Hi,

Welcome to LQ!

'How to Ask Questions the Smart Way' would be one link you should look at to help us to help you in the future.

Below are a few links to aid you in understanding;

Linux Documentation Project
Rute Tutorial & Exposition
Linux Command Guide
Utimate Linux Newbie Guide
LinuxSelfHelp
Getting Started with Linux
Bash Reference Manual
Advanced Bash-Scripting Guide
Linux Home Networking
Virtualiation- Top 10

:hattip:
The above links and others can be found at 'Slackware-Links'. More than just SlackwareŽ links!

pr_deltoid 06-10-2010 01:27 PM

onebuck, why do you keep posting so many links on every thread? New people are going to show up here all the time, you're going to have 50,000 posts with 5,000,000 links. Keep it simple. ;)
Besides that, "how to ask questions the smart way" is already in your signature. This is the second thread I've opened in newbie within 5 minutes where you've double posted your signature and links.

onebuck 06-10-2010 02:26 PM

Hi,

Quote:

Originally Posted by prdeltoid (Post 3999308)
onebuck, why do you keep posting so many links on every thread? New people are going to show up here all the time, you're going to have 50,000 posts with 5,000,000 links. Keep it simple. ;)
Besides that, "how to ask questions the smart way" is already in your signature. This is the second thread I've opened in newbie within 5 minutes where you've double posted your signature and links.

You post in the manner that abides by the LQ rules as I will continue. If you feel that my recommendations are not proper that's your opinion. I will continue to post the information as I see warranted.

No violation of the LQ rules.

As for the separation of the link within my signature. That is to point out helpful informational statements. Again one form of communication. You don't have to read what I post. So get over it!

pixellany 06-10-2010 04:36 PM

onebuck;

Please continue doing things exactly as you have been. Old-timers know they are free to ignore, and the newcomers will learn in due course

pr_deltoid 06-10-2010 04:49 PM

From How To Ask Questions The Smart Way:
Quote:

Community standards do not maintain themselves: They're maintained by people actively applying them, visibly, in public. Don't whine that all criticism should have been conveyed via private e-mail: That's not how it works. Nor is it useful to insist you've been personally insulted when someone comments that one of your claims was wrong, or that his views differ. Those are loser attitudes.
Quote:

Remember: When that hacker tells you that you've screwed up, and (no matter how gruffly) tells you not to do it again, he's acting out of concern for (1) you and (2) his community. It would be much easier for him to ignore you and filter you out of his life.

MTK358 06-10-2010 04:56 PM

Sorry if this offends anyone, but I'm with prdeltoid on this.

pixellany 06-10-2010 08:02 PM

I know that I was part of the diversion, but this thread now needs to go back to the original topic.

If there is any issue with a member's post, the correct action is to report it.


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