Inserting values into database from an excel


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Inserting values into database from an excel
# 1  
Old 05-31-2016
Inserting values into database from an excel

Hi,


I have a requirement where I have an excel sheet with the below values

Code:
 COL1        COL2       COL3
 Germany   URGENT   NORMAL

I want to cut the values of this excel in such a way that I get the values and pass it to an insert statement

Code:
update tbfin set value1=COL2,value2=col3 where table_name=col1;

can you please help with the logic for the same ?



Moderator's Comments:
Mod Comment Please use code tags as required by forum rules!

Last edited by RudiC; 05-31-2016 at 06:56 AM.. Reason: Added code tags.
# 2  
Old 05-31-2016
Any attempts/ideas/thoughts from your side?
# 3  
Old 05-31-2016
Anyway, here we go. I'm afraid I can't EXACTLY replicate your desired output as
- it is NOT an insert (as requested) but an update statement
- the case of line 1 field 2 & 3 don't match the output and can't be made up THAT easy.

On top, it's NOT easy (again) to extract from EXCEL immediately although there seems to exist a perl module therefor. I'll assume you created a <TAB> delimited text file instead.

If you're fine with an approximation, try
Code:
awk 'NR == 1 {print "update tbfin set value1=" $2 ",value2=" $3 " where table_name=" $1 ";"}' file
update tbfin set value1=COL2,value2=COL3 where table_name=COL1;

If you don't want the header info but the data, replace NR == 1 with NR > 1 or drop it entirely if you want ALL lines represented.
This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Inserting values to database

hi , I'm new to Unix shell scripting. I need help to insert read csv which has two columns -emp no and logged date. csv file is a large file so i want to keep the insertion query in a separate .sql file. csv file looks this: empno | loggeddate ___________________ 5666 ,... (5 Replies)
Discussion started by: preema
5 Replies

2. Shell Programming and Scripting

Inserting script variables into database

I have a script working out ink percentages #!/bin/bash currentcyan=$'iso.3.6.1.2.1.43.11.1.1.9.1.1 = INTEGER: 990' currentmagenta=$'iso.3.6.1.2.1.43.11.1.1.9.1.2 = INTEGER: 972' currentyellow=$'iso.3.6.1.2.1.43.11.1.1.9.1.3 = INTEGER: 972' currentblack=$'iso.3.6.1.2.1.43.11.1.1.9.1.4 =... (1 Reply)
Discussion started by: leshy93
1 Replies

3. Shell Programming and Scripting

Problem in inserting values of variable of shell

hi all, i have one shell script like this #!/bin/bash -xv ENV_NAME=`cat $IB_HOME_DIR/cfg/ibProfile.sh | grep "RDM_CONN" | cut -f 2 -d "@"` CURRENT_DIR=`pwd`; string=$IB_HOME_DIR string1="$string/FRGFOLDER/input" #sed "s/string3/$string1" frg_event_src.sql > modifiedinsert.sql sqlplus... (2 Replies)
Discussion started by: ramsavi
2 Replies

4. Shell Programming and Scripting

Need help on inserting data from text file to excel using shell script

Hi, Please help me on this. I want to insert data from text file to excel using shell script nawk -v r=4 -v c=4 -v val=$a -F, 'BEGIN{OFS=","}; NR != r; NR == r {$c = val; print}' "file.csv" I used above one to insert $a value in 4th row, 4th column in an excel file.csv and it... (3 Replies)
Discussion started by: suman.frnz
3 Replies

5. Shell Programming and Scripting

Inserting variable values in filename

Hi All, I have a directory containing multiple files. and also a txt file which contains the list of all filenames and certain values. I want to read the text file line by line and if its 2nd column is matched with the filename in directory, then it must insert the values in 7th column to... (14 Replies)
Discussion started by: CAch
14 Replies

6. Shell Programming and Scripting

Script for Logfile Inserting into the Database

Here's the problem. I have a shell script running for every one minute as cronjob that outputs to a log file. I want to be able to take the data from the log file and insert it into a mysql database. The script needs to run at a set period of time and remove the log file data once the insert is... (7 Replies)
Discussion started by: kgrvamsi
7 Replies

7. Shell Programming and Scripting

How to extract data into excel from a database in unix

Hello viewers, I am connecting to db2 database from unix. I am executing a query for example select * from emp. I need to export the data obtained from the above command to a excel file. Could you please suggest how to proceed on this? thanks and regards, k.n.v.santosh (3 Replies)
Discussion started by: santoshaarudhra
3 Replies

8. Shell Programming and Scripting

PERL Win32::OLE Inserting Picture in Excel

I am trying to insert a picture into a worksheet in Excel using Perl the following is the code use Win32::OLE; use Win32::OLE::Const "Microsoft Excel"; use Win32::OLE qw(in with); # Initiate Excel application $Excel = Win32::OLE->new('Excel.Application', 'Quit'); $Excel->{Visible} =1; #... (1 Reply)
Discussion started by: cold_Que
1 Replies

9. Shell Programming and Scripting

help in inserting values in date format

how to assign values in this date format a=`date +"%H%M%S"` how to give value of H=22,here in this format so that i can grep 22nd hour.Below is the script -------------------------------------------------------------------------- a=`date +"%H%M%S"` for i in *.log do cat $i | grep $a... (3 Replies)
Discussion started by: ali560045
3 Replies

10. Shell Programming and Scripting

Inserting Values From A File Into A Table

Guys, I want to insert some values from a log file into a temporary table. the values in the log file looks like this SV_NAME CC_NAME CP_DISP_RUN_STATE ------- ------------------- ----------------- sble01 ALLTEL WorkMon24Hrs Running I want to enter the... (2 Replies)
Discussion started by: ragha81
2 Replies
Login or Register to Ask a Question