LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-30-2005, 02:18 PM   #1
genderbender
Member
 
Registered: Jan 2005
Location: US
Distribution: Centos, Ubuntu, Solaris, Redhat
Posts: 396

Rep: Reputation: 31
Multiple searches?


This is part of my assignement and two of the assignment "problems" are I cant use switches and its gotta be bash (not a problem really). Its my first bash program so youll have to go easy as this is probably quite a basic question.

Ive got two database files called vehicle and customer. Heres an example of one customer in the customer file, there are others in it obviously.

customer number 3
first name steve
surname johnson
post code wm83ee
telephone number 0800123456

my vehicle database look like this:

car reg no g428nug
colour green
model audi
year of manufacture 1991
selling price 200
sold flag Y
customer number 3

I've done nearly all the script apart from this section and i dont really know where to start besides grep, but i need multiple instances of grep to search and output lots of different things and then compare them with the other file. Heres the bit im stuck on:

"Perform an audit (i.e. consistency check) of the database. You will identify all customer records with no corresponding vehicle record and all vehicle records marked as sold with no corresponding customer record."


Any help at all, even a clue as to how I'd do this would be perfect.


Thanks a LOT!
 
Old 01-30-2005, 02:51 PM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
Sorry, I'm not going to do your homework. It's against the rules of this forum anyway.

Clues? Yes, of course:
  • http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
  • http://www.tldp.org/LDP/abs/html/index.html
  • man bash
  • man cut (or: info cut)
  • man sed (or: info sed)
 
Old 01-30-2005, 03:02 PM   #3
twantrd
Senior Member
 
Registered: Nov 2002
Location: CA
Distribution: redhat 7.3
Posts: 1,438

Rep: Reputation: 52
What's also against the rules is double posting. You already have a thread on this...why create another?

-twantrd
 
Old 01-30-2005, 03:02 PM   #4
genderbender
Member
 
Registered: Jan 2005
Location: US
Distribution: Centos, Ubuntu, Solaris, Redhat
Posts: 396

Original Poster
Rep: Reputation: 31
Erm thanks, you wouldnt do my homework. Something along the lines of cat the customer file grep for number and output to a file and then grep vehicle for contents of that file would of been better and not doing my homework either!
But manual pages which arent gonna help me all that much are pretty useless. Isnt cut essentially deleting bits of files, like any text ive got? And Sed for controlling output?



Problem is if i do what i just wrote ill get a file with about 8 lines all saying customer number 1 through to customer number 8. A direct problem would be how do i seperate each of these into single variables to search for in my vehicle file.


these 2 would of been more substantial
man awk (particually stuff on arrays)
man grep
man diff

sorry if i sound rude, just feel a bit humiliated and sorry i didnt read the rules of the forum
 
Old 01-30-2005, 03:05 PM   #5
genderbender
Member
 
Registered: Jan 2005
Location: US
Distribution: Centos, Ubuntu, Solaris, Redhat
Posts: 396

Original Poster
Rep: Reputation: 31
OK sorry, my other posts are different problems though I'll shut up and go and hide in a cave. Sorry once again
 
Old 01-30-2005, 03:57 PM   #6
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
Quote:
Originally posted by genderbender
Erm thanks, you wouldnt do my homework. Something along the lines of cat the customer file grep for number and output to a file and then grep vehicle for contents of that file would of been better and not doing my homework either!
I admit you have got half a point there.

Quote:
But manual pages which arent gonna help me all that much are pretty useless.
Probably true. Man pages generally are reference documents, which assume you already know how things work. For newbie's they can be pretty useless.

On the other hand, those web-links I posted, are step-by-step guides. Very readable. After working seriously through those, you know much more about bash than you need for this assignment. Similar doc's exist for e.g. awk.

Quote:
Problem is if i do what i just wrote ill get a file with about 8 lines all saying customer number 1 through to customer number 8. A direct problem would be how do i seperate each of these into single variables to search for in my vehicle file.
OK. I'll help you get going with that part (I feel a little bad. And helping with some perticular issue should OK)
customer.txt:
Code:
customer number 1
first name steve
surname johnson
post code wm83ee
telephone number 0800123456

customer number 2
first name heiko
surname noordhof
post code xc24df
telephone number 0503187138

customer number 3
first name ronald
surname reagan
post code xqqqqq
telephone number 004411223
cars.txt:
Code:
car reg no g428nug
colour green
model audi
year of manufacture 1991
selling price 200
sold flag Y
customer number 2

car reg no u477abc
colour blue
model toyota
year of manufacture 1992
selling price 230
sold flag Y
customer number 1
dbscript.sh
Code:
#!/bin/bash

grep 'customer number' customer.txt | while read CUST ; do
	unset CARREG
	cat cars.txt | while read LINE ; do
		if echo "$LINE" | grep -q 'car reg' ; then
			CARREG="$LINE"
		fi
		if echo "$LINE" | grep -q 'customer' ; then
			if [ "$LINE" == "$CUST" ] ; then
				echo "$CUST bought $CARREG"
			fi
		fi
	done
done
Quote:
sorry if i sound rude, just feel a bit humiliated
I'm sorry about that.
It irritates me when people ask questions like "This is my homework", and then expect people here to help them cheat at school/college. If they don't want to learn programming, that's their choice. People here generally like to help other people learn something, but doing their homework is the opposite (then they learn nothing) and wasting my time. At least that's how I feel.

But when you got stuck, it's of course OK to ask here. But in that case there will be posted some code, or at least some specific question. I feel people having a question, could at least takes some time actually ask some specific question. Just: "This is my homewerk, PLEASE HELP!!!" doesn't cut it.

I guess, your question was somewhere in the middle. And I may have been a little harsh on you in my first reply.
 
Old 01-30-2005, 04:11 PM   #7
genderbender
Member
 
Registered: Jan 2005
Location: US
Distribution: Centos, Ubuntu, Solaris, Redhat
Posts: 396

Original Poster
Rep: Reputation: 31
OK, thanks a lot Now for the next bit of my homework, just kidding

But thanks for making me look considerbly less stupid and for helping me out more than substantially. Your right I could of thought that post out a little better, definetly! I wouldnt of posted at all if I'd of known I wasnt allowed help with skool work. So am sorry about that.

I dont get much support with this at all though, I've done C++ and java and whilst they bare some resemblance it doesnt directly relate, just some ideas. My dads learning perl and insists I write the whole thing in perl complete with switch statements all over the place and the bloke teaching us despises programming. I should of read more though, see now I've gone from feeling like a complete moron to feeling guilty... not good.


Anyway sorry for being so rude and I'm really sorry for breaking rules. Next time I post its gonna be a completed bit of code All 100+ lines of it :S


Thanks a lot
 
Old 01-30-2005, 04:20 PM   #8
genderbender
Member
 
Registered: Jan 2005
Location: US
Distribution: Centos, Ubuntu, Solaris, Redhat
Posts: 396

Original Poster
Rep: Reputation: 31
Just seen duplicate post... I pressed stop and spell checked then pressed send again. Sorry about that, complete accident.
 
  


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
Save favorite searches username17 LQ Suggestions & Feedback 3 05-28-2005 08:40 AM
Making searches more precise? rose_bud4201 LQ Suggestions & Feedback 1 04-26-2005 06:09 PM
different searches... gfrair Linux - Newbie 9 03-13-2005 07:15 PM
Multiple searches (sorry if this is a long thread) genderbender Programming 2 01-30-2005 06:03 PM
Searches Thulemanden LQ Suggestions & Feedback 1 12-05-2004 10:26 AM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration