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 06-09-2010, 11:00 PM   #1
mohamad
LQ Newbie
 
Registered: Jun 2010
Posts: 11

Rep: Reputation: 0
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?!
 
Old 06-09-2010, 11:10 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
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.
 
Old 06-09-2010, 11:13 PM   #3
mohamad
LQ Newbie
 
Registered: Jun 2010
Posts: 11

Original Poster
Rep: Reputation: 0
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
 
Old 06-10-2010, 01:02 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,344

Rep: Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746
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
 
Old 06-10-2010, 05:40 AM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
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.
 
Old 06-10-2010, 07:03 AM   #6
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
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
 
Old 06-10-2010, 08:13 AM   #7
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,922
Blog Entries: 44

Rep: Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158
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


The above links and others can be found at 'Slackware-Links'. More than just SlackwareŽ links!
 
Old 06-10-2010, 01:27 PM   #8
pr_deltoid
Member
 
Registered: Jun 2010
Distribution: Fedora
Posts: 289

Rep: Reputation: 41
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.
 
Old 06-10-2010, 02:26 PM   #9
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,922
Blog Entries: 44

Rep: Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158
Hi,

Quote:
Originally Posted by prdeltoid View Post
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!
 
Old 06-10-2010, 04:36 PM   #10
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
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
 
Old 06-10-2010, 04:49 PM   #11
pr_deltoid
Member
 
Registered: Jun 2010
Distribution: Fedora
Posts: 289

Rep: Reputation: 41
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.
 
Old 06-10-2010, 04:56 PM   #12
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Sorry if this offends anyone, but I'm with prdeltoid on this.
 
Old 06-10-2010, 08:02 PM   #13
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
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.

Last edited by pixellany; 06-10-2010 at 08:15 PM.
 
  


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
[SOLVED] Find URL in Debian package index via awk/sed (=find a line, then search from there) maddes.b Linux - Software 11 06-28-2013 07:37 AM
Find with -exec argument - not giving proper output..how to find... hinetvenkat Linux - Server 4 01-25-2010 06:19 AM
Find/grep/wc command to find matching files, print filename and word count dbasch Linux - Newbie 10 09-14-2009 05:55 PM
Single find command to find multiple files? thok Linux - Newbie 7 01-31-2009 04:45 PM
Is there a way to find recently created/edited files without using find? BrianK Linux - General 2 10-15-2007 09:41 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:51 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
Open Source Consulting | Domain Registration