How to read a text file line by line and insert into a database table?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to read a text file line by line and insert into a database table?
# 1  
Old 10-08-2014
How to read a text file line by line and insert into a database table?

I have a test file that I want to read and insert only certain lines into the
the table based on a filter.

1. Rread the log file 12 Hours back Getdate() -12 Hours
2. Extract the following information on for lines that say "DUMP is
complete"
A. Date
B. Database Name
C. Phrase "Dump is Complete"
3 Insert three extracted data columns into a Database table
4. Perform select and output result to html and email






Code:
 
Feb 10 23:20:27 2014: Backup Server: 4.188.1.1: Database EligKeyDB: 14675188 kilobytes (86%) DUMPED.
Feb 10 23:20:54 2014: Backup Server: 4.188.1.1: Database EligKeyDB: 14841824 kilobytes (87%) DUMPED.
Feb 10 23:21:06 2014: Backup Server: 4.188.1.1: Database EligKeyDB: 14968036 kilobytes (89%) DUMPED.
Feb 10 23:21:20 2014: Backup Server: 4.188.1.1: Database EligKeyDB: 15119660 kilobytes (91%) DUMPED.
Feb 10 23:21:36 2014: Backup Server: 4.188.1.1: Database EligKeyDB: 15259614 kilobytes (94%) DUMPED.
Feb 10 23:21:48 2014: Backup Server: 3.43.1.1: Dump phase number 1 completed.
Feb 10 23:21:48 2014: Backup Server: 3.43.1.1: Dump phase number 2 completed.
Feb 10 23:21:48 2014: Backup Server: 3.43.1.1: Dump phase number 3 completed.
Feb 10 23:21:48 2014: Backup Server: 4.188.1.1: Database EligKeyDB: 15387946 kilobytes (100%) DUMPED.
Feb 10 23:21:48 2014: Backup Server: 3.42.1.1: DUMP is complete (database EligKeyDB).
Feb 10 23:21:48 2014: Backup Server: 2.23.1.1: Connection from Server CBSPRO on Host DSHSSAVWN8 with HostProcid 4688.
Feb 10 23:21:48 2014: Backup Server: 2.23.1.1: Connection from Server CBSPRO on Host DSHSSAVWN8 with HostProcid 4688.

# 2  
Old 10-09-2014
You are asing us to write the entire script
What have you tried?
what database are you inserting these details into?
# 3  
Old 10-09-2014
Bumping up posts or double posting is not permitted in these forums.

Please read the rules, which you agreed to when you registered, if you have not already done so.

You may receive an infraction for this. If so, don't worry, just try to follow the rules more carefully. The infraction will expire in the near future

Thank You.

The UNIX and Linux Forums.

(Original thread is here)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script UNIX to read text file line by line

i have a text file as belows, it includes 2 columns, 1st is the column name, 2nd is the file_name data_file.txt column_name file_name col1 file1 col2 file2 col3 file1 col4 file1 col5 file2 now, i would like to... (4 Replies)
Discussion started by: tester111
4 Replies

2. UNIX for Beginners Questions & Answers

Insert a line of text on nth line of a file

Hi All, I am using UNix Sun OS sun4u sparc SUNW,SPARC-Enterprise My intention is to insert a line of text after 13th line of every file inside a particular directory. While trying to do it for a single file , i am using sed sed '3 i this is the 4th line' filename sed: command garbled: 3... (5 Replies)
Discussion started by: gotamp
5 Replies

3. UNIX for Dummies Questions & Answers

Insert a line in a text file

I want to insert a line with text after the 9th line of a text file. How would I do this using sed or awk? (2 Replies)
Discussion started by: lost.identity
2 Replies

4. Shell Programming and Scripting

Shell script to read a text file line by line & process it...

Hi , I am trying to write an shell, which reads a text file (from a location) having a list of numbers of strictly 5 digits only ex: 33144 Now my script will check : 1) that each entry is only 5 digits & numeric only, no alphabets, & its not empty. 2)then it executes a shell script called... (8 Replies)
Discussion started by: new_to_shell
8 Replies

5. Shell Programming and Scripting

Read text file line by line

Hi everyone, I am writing a BASH shell script that I will use to process data files. I have a text file that contains the names of the files to be processed, for example: cat filenames.txt file1 file2 file3 file4 file5 What I would like to do is set up a FOR loop within my script... (2 Replies)
Discussion started by: msb65
2 Replies

6. Web Development

INSERT data to a Database Table from a text file

If you have a text file and if you want to Insert data to your Database Table, You can do it with these queries LOAD DATA LOCAL INFILE '/path/yourTextFile.txt' INTO TABLE yourTableName FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '\\' LINES TERMINATED BY '\n' (0 Replies)
Discussion started by: sitex
0 Replies

7. Shell Programming and Scripting

bash: read file line by line (lines have '\0') - not full line has read???

I am using the while-loop to read a file. The file has lines with null-terminated strings (words, actually.) What I have by that reading - just a first word up to '\0'! I need to have whole string up to 'new line' - (LF, 10#10, 16#A) What I am doing wrong? #make file 'grb' with... (6 Replies)
Discussion started by: alex_5161
6 Replies

8. Shell Programming and Scripting

How to insert some constant text at beginig of each line within a text file.

Dear Folks :), I am new to UNIX scripting and I do not know how can I insert some text in the first column of a UNIX text file at command promtp. I can do this in vi editor by using this command :g/^/s//BBB_ e,g I have a file named as Test.dat and it containins below text: michal... (4 Replies)
Discussion started by: Muhammad Afzal
4 Replies

9. Shell Programming and Scripting

Insert a line in a text file

So I need to write lines into line X of file X. I can get the file by doing: cfgnumber=$(cat -n -comm.cfg| grep -i "servicegroup_name 24x7-comunicacions") echo $cfgnumber it outputs the Line where it finds now I need to start writing something right bellow that line. thanks (10 Replies)
Discussion started by: 4scriptmoni
10 Replies

10. Shell Programming and Scripting

Insert text file at a certain line.

I need to insert a file called temp_impact (which has about 15 lines in it) to a file called 11.23cfg starting at line 33. I searched the forums and found the sed '34i\ test' 11.23cfg > newfile That will enter word test at the appropriate line, but i need the entire file dumped there. Any... (4 Replies)
Discussion started by: insania
4 Replies
Login or Register to Ask a Question