LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 09-27-2013, 06:46 AM   #46
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444

I think you did really well with that,
it was a long time before my scripts were anything more and a few lines of simple commands, couldn't even call them scripts

Database is not something I've ever done
just a few queries , and some data addition/deletion/modification
 
Old 09-27-2013, 07:27 AM   #47
sparky90ful
Member
 
Registered: Sep 2013
Posts: 30

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Firerat View Post
just a few queries , and some data addition/deletion/modification
That's what i must do so can you explain me what i must do to do that?
 
Old 09-27-2013, 08:05 AM   #48
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
basically , read the manual

they will usually have some examples/tutorials, then you just build on that

what database will you be using?
search on line

example, mysql
https://startpage.com/do/search?q=mysql+manual
 
Old 09-27-2013, 08:28 AM   #49
sparky90ful
Member
 
Registered: Sep 2013
Posts: 30

Original Poster
Rep: Reputation: Disabled
I have no idea .....the project tells me that:

synopsys:
bdsh.sh [-k] [-f <db_file>] (
put <clef> <valeur> |
del <clef> [<valeur>] |
select [<expr>] )

Write a script shell emulating simple functions of a database
That base must be contained in a unique file named sh.db where we will be able to give another name in parameter thanks to "-f" option
the script parameters will be the next ones:

-put <clef> <valeur> :
*adds a key <clef> who contain the value <valeur>
*if the key allready exist the value will be crushed
*nothing is displayed

-del <clef>:
*delete the value of key <clef>
*if the key doesn't existe it nothing passed
*nothing is displayed


-select [<expr>]:
*displays the values ​​whose keys match at <expr> or all values ​​if no parameter is puted.
*this is the matching of the grep command used.
*be used to display the file order, which will be in the chronological order of insertion.

so i don't know how to start and i dont know if i will be able to do it or if is mysql or i don't know what

Last edited by sparky90ful; 09-27-2013 at 08:32 AM.
 
Old 09-27-2013, 08:49 AM   #50
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
ahh,

no it is not an actual database

they want you to write a shell script that act like a database


sh.db is a file were you store everything

bdsh.sh is the script which manages the data in sh.db

I was going to say bash arrays, but no... too much here
they just want something simple


sed and grep are your friends here

I guess this is OSX again?
sed might be a little odd, grep should be fine
 
Old 09-27-2013, 08:55 AM   #51
sparky90ful
Member
 
Registered: Sep 2013
Posts: 30

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Firerat View Post
ahh,

no it is not an actual database

they want you to write a shell script that act like a database


sh.db is a file were you store everything

bdsh.sh is the script which manages the data in sh.db

I was going to say bash arrays, but no... too much here
they just want something simple


sed and grep are your friends here

I guess this is OSX again?
sed might be a little odd, grep should be fine
thanks for the hints
yes OSX is the school pc is un iMac.Every day we must go at school 9h-23h no weekend no holidays and do cods.......
Sooo what i must do is to read the user input store in a file and when the user will call it to dysplay it? Something like that?
 
Old 09-27-2013, 09:41 AM   #52
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
basically yes

as well as overwrite existing value, or delete it

sed for your writes
grep for your reads


since I think most of the sed examples/tutorials ( "sed one liners" is a good search ) you find with be "gnu sed"
I will give you this

sed -i
saves changes "inline" to teh file you are working with
gnu sed will happily do this without making a backup
but BSD's sed -i expects a backup suffix, and takes the next non-space to be it, which breaks your expresion

so, you either need to have a backup

sed -i .backup
# gnu sed is sed -i.backup #
OR, give it 'nothing'

sed -i "" <rest of your sed>

probably some other differences , but for what you need right now, you should be ok
 
Old 09-27-2013, 09:46 AM   #53
sparky90ful
Member
 
Registered: Sep 2013
Posts: 30

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Firerat View Post
basically yes

as well as overwrite existing value, or delete it

sed for your writes
grep for your reads


since I think most of the sed examples/tutorials ( "sed one liners" is a good search ) you find with be "gnu sed"
I will give you this

sed -i
saves changes "inline" to teh file you are working with
gnu sed will happily do this without making a backup
but BSD's sed -i expects a backup suffix, and takes the next non-space to be it, which breaks your expresion

so, you either need to have a backup

sed -i .backup
# gnu sed is sed -i.backup #
OR, give it 'nothing'

sed -i "" <rest of your sed>

probably some other differences , but for what you need right now, you should be ok
Thanks i will try things i wil come back with answers to tell my progress
Can you make a little cod 5 6 lines to have a little idea please?

Last edited by sparky90ful; 09-27-2013 at 10:03 AM.
 
Old 09-27-2013, 10:25 AM   #54
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
have a look at getopts, for your -put -del -select

test if sh.db exists, if not create ( just touch )

have a function for each of the options

put () {
does key exist in sh.db? # grep for that )
if not, send Key=value to sh.db # simple redirection >>
if yes, use sed to overwrite existing Key-value
return
}

once you get started, you will be fine

getopts to start
 
Old 09-27-2013, 10:35 AM   #55
sparky90ful
Member
 
Registered: Sep 2013
Posts: 30

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Firerat View Post
once you get started, you will be fine
That's the idea after you get succsed 2 3 lines is quite easy then
Thanks very much for info

how do y do this please??
in my file i have
11=a
12=b
13=c
so if <key> exist (with grep ) how do i tell him cuz he must replace the value who corespond at that key but who is after "="
thanks in advancei have this
Code:
path=$0
comand=$1
key=$2
val=$3


 if [[ "$comand" = "put" ]];then
	  put
    else
echo "   \"$path $comand INVALID FUNCTION : $comand\"   "  	
fi

 put(){

	if [[ "`grep "$key" /home/florea_g/BDSH/florea_g/sh.sh | cut -d "=" -f2`" = "$key" ]]
		then
		sed -i ''
	else

     echo "$key=$val">>sh.sh

}

Last edited by sparky90ful; 09-27-2013 at 12:11 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] Date and Time Calculations in Perl (or other) taylor_ma Programming 9 05-03-2012 09:27 PM
[SOLVED] Date Calculations using script!! anishkumarv Linux - Newbie 9 09-24-2011 04:36 PM
Using Perl to perform calculations in Bash w1k0 Programming 5 06-07-2009 09:10 PM
Date calculations on Sun sparc ukursat Linux - Newbie 1 12-05-2008 11:01 PM
Date calculations in BASH script Crashman Programming 4 07-03-2004 11:15 AM


All times are GMT -5. The time now is 03:58 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration