LinuxQuestions.org
Visit Jeremy's Blog.
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 12-06-2003, 03:08 PM   #1
1rulesall
LQ Newbie
 
Registered: Dec 2003
Location: Phoenix, AZ
Posts: 3

Rep: Reputation: 0
How do I select a row of info in a database file?


Help me if you can.

I am just learning Linux, using Bash. I have a small program that uses a menu to add, delete, search, and find players on a team roster. The roster list of players (database) is made of 6 fields, separated by colons. For example:

Entry#:Last Name:First Name:Position:Year:Phone Number

My problem is when my script runs to search for a player, which searches by entry #, there are sometimes multiple players listed.

The search script uses a grep command, and finds numbers in the entry # column and the phone # column.

Can I limit a grep command to search just the first column?

Thanks,

1rulesall!
 
Old 12-06-2003, 04:08 PM   #2
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
Look into 'cut' - then pipe that to grep. Though I'm sure there's a million ways to do it and you'll get several suggestions and at least one person will tell you to write in perl.
 
Old 12-06-2003, 04:15 PM   #3
h/w
Senior Member
 
Registered: Mar 2003
Location: New York, NY
Distribution: Debian Testing
Posts: 1,286

Rep: Reputation: 46
use perl!
 
Old 12-06-2003, 04:17 PM   #4
h/w
Senior Member
 
Registered: Mar 2003
Location: New York, NY
Distribution: Debian Testing
Posts: 1,286

Rep: Reputation: 46
i was kidding. i have never used perl, and not had enough interest in it either.
 
Old 12-06-2003, 09:23 PM   #5
1rulesall
LQ Newbie
 
Registered: Dec 2003
Location: Phoenix, AZ
Posts: 3

Original Poster
Rep: Reputation: 0
Ok,
thanks digiot for replying.
But how do I cut the fifth row and only the fifth row of a roster list that's about 30 rows long
 
Old 12-07-2003, 12:02 AM   #6
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
Did you check the man page? It'd be something like 'cut -d: -f5 | grep thing-I-want-to-find'

Oh. Oops. Row? Or column? Cut will chop a column from a line and grep will 'cut' a line from a list, so to speak. Come to think of it, cut's no good if you're wanting to extract the whole line. I don't really know regular expressions but, if the problem is that you have numbers at the beginning (numbering entries) and numbers at the end (phone numbers) and 'grep 5' gives you row 5 *and* everybody whose phone number has a five in it, then 'grep ^5' will do it. That basically means 'lines beginning with 5'. That's only useful for that specific, and I don't know that that's your complete situation, but you can do far more complicated stuff with those principles, anyway.
 
Old 12-08-2003, 08:27 PM   #7
1rulesall
LQ Newbie
 
Registered: Dec 2003
Location: Phoenix, AZ
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks for the help

Thanks digiot,

That's exactly the situation I was looking for. Much appreciated. I will go try it.

Thanks again,

1rulesall.
 
  


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
RPM Database Info apocolpse Linux - Newbie 6 11-02-2005 01:17 PM
Convert an info file(bash.info.gz) to a single html file Darwish Linux - Software 2 09-24-2005 06:51 AM
How To Put Values In Select Box From Database In Jsp nimishabhatia Programming 1 07-20-2005 01:16 PM
C++ read csv file row into vector taban1 Programming 3 11-08-2004 02:01 PM
database for system/network info pipio Linux - Software 2 06-15-2004 03:36 PM

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

All times are GMT -5. The time now is 04:14 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