LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-15-2014, 03:14 PM   #16
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,237

Rep: Reputation: 1655Reputation: 1655Reputation: 1655Reputation: 1655Reputation: 1655Reputation: 1655Reputation: 1655Reputation: 1655Reputation: 1655Reputation: 1655Reputation: 1655

Ok. You have errors in your script.

1) _name= echo $F | cut -d\| -f1
This is not going to do what you think. You want to perform an action and take its output and place it in a variable, so this is more adequate:
Code:
_name=$(echo $F | cut -d\| -f1)
2) values ($uuname ,
This $uuname is referenced nowhere else in the script, also it isnt in quotes. Assuming you want that to be first name then:
Code:
values ('$_name',
3) Assuming an input of:
Code:
[root@dev ~]# cat list.list
name1|lastname1|address1|tele1
name2|lastname2|address2|tele2
name3|lastname3|address3|tele3
name4|lastname4|address4|tele4
You can fix your script by doing the above, and get this:

Code:
[root@dev ~]# ./your_script.sh
name1|lastname1|address1|tele1
lastname1
lastname1
lastname1
lastname1
address1
address1
address1
address1
tele1
tele1
tele1
tele1
insert into testable (name,lastname,address,telephone) values ('name1', 'lastname1', 'address1' , 'tele1')  ;
name2|lastname2|address2|tele2
lastname2
lastname2
lastname2
lastname2
address2
address2
address2
address2
tele2
tele2
tele2
tele2
insert into testable (name,lastname,address,telephone) values ('name2', 'lastname2', 'address2' , 'tele2')  ;
name3|lastname3|address3|tele3
lastname3
lastname3
lastname3
lastname3
address3
address3
address3
address3
tele3
tele3
tele3
tele3
insert into testable (name,lastname,address,telephone) values ('name3', 'lastname3', 'address3' , 'tele3')  ;
name4|lastname4|address4|tele4
lastname4
lastname4
lastname4
lastname4
address4
address4
address4
address4
tele4
tele4
tele4
tele4
insert into testable (name,lastname,address,telephone) values ('name4', 'lastname4', 'address4' , 'tele4')  ;

Last edited by szboardstretcher; 05-15-2014 at 03:23 PM.
 
1 members found this post helpful.
Old 05-15-2014, 03:22 PM   #17
tripialos
Member
 
Registered: Apr 2012
Posts: 169

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by szboardstretcher View Post
and what is in list.list?
Code:
root@chefnode:~/mysql#
root@chefnode:~/mysql# cat list.list
Shad|Morris|Buizingen|032-836-9436
root@chefnode:~/mysql#
 
Old 05-15-2014, 03:34 PM   #18
michaelk
Moderator
 
Registered: Aug 2002
Posts: 20,436

Rep: Reputation: 3560Reputation: 3560Reputation: 3560Reputation: 3560Reputation: 3560Reputation: 3560Reputation: 3560Reputation: 3560Reputation: 3560Reputation: 3560Reputation: 3560
What the heck was I thinking... No one has to answer that...

bash does not like spaces between the =

_name=$(echo $F | cut -d\| -f1)
_lastname=$(echo $F | cut -d\| -f2)
_address=$(echo $F | cut -d\| -f3)
_tel=$(echo $F | cut -d\| -f4)

echo "INSERT INTO TABLENAME (name,lastname,address,telephone) VALUES ('$_name', '$_lastname', '$_address', '$_tel');"

INSERT INTO TABLENAME (name,lastname,address,telephone) VALUES ('Shad', 'Morris', 'Buizingen', '032-836-9436');

A bit late...

Last edited by michaelk; 05-15-2014 at 03:35 PM.
 
1 members found this post helpful.
Old 05-15-2014, 03:48 PM   #19
tripialos
Member
 
Registered: Apr 2012
Posts: 169

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
What the heck was I thinking... No one has to answer that...

bash does not like spaces between the =

_name=$(echo $F | cut -d\| -f1)
_lastname=$(echo $F | cut -d\| -f2)
_address=$(echo $F | cut -d\| -f3)
_tel=$(echo $F | cut -d\| -f4)

echo "INSERT INTO TABLENAME (name,lastname,address,telephone) VALUES ('$_name', '$_lastname', '$_address', '$_tel');"

INSERT INTO TABLENAME (name,lastname,address,telephone) VALUES ('Shad', 'Morris', 'Buizingen', '032-836-9436');

A bit late...
NOW THAT I DIDNT KNOW...!!!!

well...i learned today

Thanks everyone for your help.

Thanks michael for solving the mistery :-D
 
Old 05-15-2014, 04:06 PM   #20
tripialos
Member
 
Registered: Apr 2012
Posts: 169

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by szboardstretcher View Post
Ok. You have errors in your script.

1) _name= echo $F | cut -d\| -f1
This is not going to do what you think. You want to perform an action and take its output and place it in a variable, so this is more adequate:
Code:
_name=$(echo $F | cut -d\| -f1)
2) values ($uuname ,
This $uuname is referenced nowhere else in the script, also it isnt in quotes. Assuming you want that to be first name then:
Code:
values ('$_name',
3) Assuming an input of:
Code:
[root@dev ~]# cat list.list
name1|lastname1|address1|tele1
name2|lastname2|address2|tele2
name3|lastname3|address3|tele3
name4|lastname4|address4|tele4
You can fix your script by doing the above, and get this:

Code:
[root@dev ~]# ./your_script.sh
name1|lastname1|address1|tele1
lastname1
lastname1
lastname1
lastname1
address1
address1
address1
address1
tele1
tele1
tele1
tele1
insert into testable (name,lastname,address,telephone) values ('name1', 'lastname1', 'address1' , 'tele1')  ;
name2|lastname2|address2|tele2
lastname2
lastname2
lastname2
lastname2
address2
address2
address2
address2
tele2
tele2
tele2
tele2
insert into testable (name,lastname,address,telephone) values ('name2', 'lastname2', 'address2' , 'tele2')  ;
name3|lastname3|address3|tele3
lastname3
lastname3
lastname3
lastname3
address3
address3
address3
address3
tele3
tele3
tele3
tele3
insert into testable (name,lastname,address,telephone) values ('name3', 'lastname3', 'address3' , 'tele3')  ;
name4|lastname4|address4|tele4
lastname4
lastname4
lastname4
lastname4
address4
address4
address4
address4
tele4
tele4
tele4
tele4
insert into testable (name,lastname,address,telephone) values ('name4', 'lastname4', 'address4' , 'tele4')  ;

Thanks buddy you saved the day :-D
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert into FOREIGN KEY field in a MySQL table rootaccess Linux - Newbie 2 06-12-2012 04:26 PM
How do I INSERT IGNORE the current date into a table in MYSQL? resetreset Programming 9 12-15-2008 01:39 AM
mysql insert using bash script venki Linux - General 3 07-07-2007 04:52 AM
Howto insert a pdf document into a mysql table jadewarrior Linux - Server 4 02-23-2007 05:18 AM
Mysql - Howto insert 'admin' account into table ??? b:z Linux - General 6 03-29-2005 03:44 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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