extracting data and store in database


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting extracting data and store in database
# 1  
Old 01-25-2008
extracting data and store in database

Hello all,
I have this text file data. The data are separated by comma in three column and space or line feed to start a new row
Code:
anderson helberg, Jane, brother
Sister ,mother,grandpa
bombay,new york, china

I would like store them in the following format.
Code:
field1                           field2                              field3
anderson helberg              Jane                               brother
bombay                         new york                         china

my problem is how to implemet the script with both line feed or single space or multiple space and comma separator to separate the rows and stores the data as shown above.
by using cut and delimiter.
Code:
anderson helberg=`echo "$text" | cut -f 1 -d','`

please anyone with help appreciated
# 2  
Old 01-29-2008
Your example doesn't match the description though,,, 'space or line feed to start a new row' isn't what you show. Your example shows it starting a new row on line feed only, and treating space as part of the field.
I'll use the output (ie line feed seperation only) as the goal here.

You can cheat and just use sed to substitute commas for tabs but it won't make a very pretty layout.
Otherwise, printf would probably be the way to go here:
Code:
#!/bin/sh
printf "%10s    %10s    %10s\n" "field1" "field2" "field3"
while read line
do
    printf "%10s    %10s    %10s\n" "`echo $line | cut -d ',' -f 1`" "`echo $line | cut -d ',' -f 2`" "`echo $line | cut -d ',' -f 3`"
done

# 3  
Old 01-29-2008
Can you try this out
(You have to work out in order to format properly)
echo "field1 field2 field3"
while IFS="," read a b c
do
echo "$a $b $c"
done < FileName
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to store "scp" results in a database table?

Hi, When I use scp to copy a file from other location, I get the output like filename, time taken etc on console. I want to store that into a database table (in oracle). Could someone give me some pointers on how to achieve this? Regards, Sachin Vaidya (1 Reply)
Discussion started by: notthatsachin
1 Replies

2. Programming

How to extract data from CVS log files and store it in database ?

Am currently working on CVS projects .. I have generated the cvs log file which is in the RCS file format . .I want to extract file path ,total revision ,date ,author and message from that file . .I want a program in java which would extract the data from cvs log file. .Pls help me out.. My... (0 Replies)
Discussion started by: EVERSOFT
0 Replies

3. Shell Programming and Scripting

Extracting specific lines of data from a file and related lines of data based on a grep value range?

Hi, I have one file, say file 1, that has data like below where 19900107 is the date, 19900107 12 144 129 0.7380047 19900108 12 168 129 0.3149017 19900109 12 192 129 3.2766666E-02 ... (3 Replies)
Discussion started by: Wynner
3 Replies

4. Shell Programming and Scripting

Execute stored procedure through script in sybase database and store the output in a .csv file

Hi, I have a sybase stored procedure which takes two input parameters (start_date and end_date) and when it get executed, it gives few records as an output. I want to write a unix script (ksh) which login to the sybase database, then execute this stored procedure (takes the input parameter as... (8 Replies)
Discussion started by: amit.mathur08
8 Replies

5. Shell Programming and Scripting

Shell Linux to connect to a database and execute store procedure

HI, i want to write a script (Linux) that: 1) connect to a database oracle 2) execute some store procedure. Can anybody help me, please? Thanks a lot Andrew (3 Replies)
Discussion started by: manichino74
3 Replies

6. UNIX and Linux Applications

Retrieving data from a database and store to a file

Hi I'm using and Oracle 10g Database. I want to write a script to retrieve data from the database and store it toa file. I'm using simple sql statements such as Select * from celltable I don't know how to specify the database name etc. I have this but it doesn't work ... (1 Reply)
Discussion started by: ladyAnne
1 Replies

7. Shell Programming and Scripting

how to split the row(array) in to fields and store in to oracle database in unix

Hi, the csv file with the delimeter #. A#B#C#D#E#F#G#H 1#2#3#4#5#6#7#8 Z#x#c#V 7#2#8#9 N. I want to read the file line by line and store in rowarray. then the rowarray content should be spilt or made to fields using the delimeter #. i am not sure can we store the fields in to... (3 Replies)
Discussion started by: barani75
3 Replies

8. UNIX for Dummies Questions & Answers

Howto capture data from rs232port andpull data into oracle database-9i automatically

Hi, i willbe very much grateful to u if u help me out.. if i simply connect pbx machine to printer by serial port RS232 then we find this view: But i want to capture this data into database automatically when the pbx is running.The table in database will contain similar to this view inthe... (1 Reply)
Discussion started by: boss
1 Replies

9. Shell Programming and Scripting

How to store Data in a File

I want to read a data from a read command and store it in a file...... Plz send me how I can do that Ex: read val and I want to store this val in a file called temp. (2 Replies)
Discussion started by: krishna_sicsr
2 Replies

10. UNIX for Advanced & Expert Users

extracting info from Unix database to construct a visual diagram

Ok heres the situation, We use Solaris 8 at work with Sybase for the db. I need to be able to easily create visual diagrams of some of our more complex systems. I've been using Visio which is such a manual process and takes a while. I was thinking maybe using Visio somehow in conjunction... (0 Replies)
Discussion started by: fusion99
0 Replies
Login or Register to Ask a Question