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?! |
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. |
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 |
Example
Code:
grep name filename There's some good bash tutorials eg http://rute.2038bug.com/index.html.gz |
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. |
Given the name, this will print the number:
Code:
echo -n 'Enter Name: ' |
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! |
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. |
Hi,
Quote:
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! |
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 |
From How To Ask Questions The Smart Way:
Quote:
Quote:
|
Sorry if this offends anyone, but I'm with prdeltoid on this.
|
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. |