Sponsored Content
Top Forums Shell Programming and Scripting To Read a File and Insert a part of the lines into the database Post 302370993 by Somanadh on Friday 13th of November 2009 05:08:11 AM
Old 11-13-2009
Question To Read a File and Insert a part of the lines into the database

Hi Guys

I need to have a shell script which reads a log file and insert a part of each line into the database. Some sample lines in the file are as below.

Code:
20091112091359 MED_RQACK     : user_data=60173054304,100232120,20091112091359,;ask_status=0;ask_reason=OK;msg_id=20091112091319
20091112091422 MED_RQACK     : user_data=60193360676,90436000,20091112091422,20091112091422;ask_status=0;ask_reason=OK;msg_id=20091112091360
20091112091441 MED_RQACK     : user_data=60192883529,77542478,20091112091441,20091112091441;ask_status=0;ask_reason=OK;msg_id=20091112091423
20091112091450 MED_RQACK     : user_data=60192818748,95312410,20091112091450,20091112091450;ask_status=0;ask_reason=OK;msg_id=20091112091442
20091112091451 MED_RQACK     : user_data=60133650310,100166770,20091112091451,;ask_status=0;ask_reason=OK;msg_id=20091112091451

What I have to do is, pick the values from (say in the first line)
60173054304,100232120,20091112091359, till the character ';'
and insert them into the database (a table).

The advantage (I guess) is that the values always start from the 42nd character of each line. I have to pick the line till I confront the character ';'. Then I have to divide that string into different fields delimited by a comma (','). Can somebody help me out on this. Smilie

Last edited by Franklin52; 11-13-2009 at 06:27 AM.. Reason: Please use code tags!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to insert data in database based on text file?

Hi....can you guys help me out in this script?? Below is a text file script....called Bukom.txt and it contains these: BUKOM 20060101 2.5 2.6 2.7 2.8 2.9 2.3 2.1 BUKOM 20060102 2.4 2.5 2.6 2.7 2.7 2.6 2.4 BUKOM 20060103 2.1 ... (9 Replies)
Discussion started by: forevercalz
9 Replies

2. Shell Programming and Scripting

How to insert data into MYSql database from a text file

Hi, Need to get help from you guys about this issue. I need to insert data into MySql database from a text file which is located in other server. The text file is something look like below: Date | SubscriberNo | Call Duration 20/7/07 | 123456788 | 20 20/7/07 | 123412344 | 30 The... (4 Replies)
Discussion started by: shirleyeow
4 Replies

3. Shell Programming and Scripting

how to insert data into database by reading it from a text file??

Hi....can you guys help me out in this script?? Below is a text file and it contains these: GEF001 000093625 MKL002510 000001 000000 000000 000000 000000 000000 000001 GEF001 000093625 MKL003604 000001 000000 000000 000000 000000 000000 000001 GEF001 000093625 MKL005675 000001... (4 Replies)
Discussion started by: pallavishetty
4 Replies

4. 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

5. Shell Programming and Scripting

read database tablename from another file

i hava a file which contains database like emp dept loc now i want to create a script that read this file line by line and create a seperate query that ll be run in database like.. DELETE FROM TRS_ONE_ATDE WHERE DATA_DT = <from file> how can this be achieved. pls help. (5 Replies)
Discussion started by: mukeshguliao
5 Replies

6. Shell Programming and Scripting

Korn shell program to parse CSV text file and insert values into Oracle database

Enclosed is comma separated text file. I need to write a korn shell program that will parse the text file and insert the values into Oracle database. I need to write the korn shell program on Red Hat Enterprise Linux server. Oracle database is 10g. (15 Replies)
Discussion started by: shellguy
15 Replies

7. Shell Programming and Scripting

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.... (2 Replies)
Discussion started by: JolietJake
2 Replies

8. Shell Programming and Scripting

Parse log file to insert into database

I have a log file that's created daily by this command: sar -u 300 288 >> /var/log/usage/$(date "+%Y-%m-%d")_$(hostname)_cpu.log It that contains data like this: Linux 3.16.0-4-amd64 (myhostname) 08/15/2015 _x86_64_ (1 CPU) 11:34:17 PM CPU %user %nice ... (12 Replies)
Discussion started by: unplugme71
12 Replies

9. Shell Programming and Scripting

Read latest log files and perform database insert

Hi Experts, I have a situation where I need to write a shell script to continuously monitor a log directory with multiple log files and perform following: 1. Read the latest log file continuously and grep "Success" OR "Failure" 2. As it capture either Success or Failure, it has to perform a... (1 Reply)
Discussion started by: rish_max
1 Replies

10. UNIX for Beginners Questions & Answers

How to make a loop to read the input from a file part by part?

Hi All, We've a VDI infrastructure in AWS (AWS workspaces) and we're planning to automate the process of provisioning workspaces. Instead of going to GUI console, and launching workspaces by selecting individual users is little time consuming. Thus, I want to create them in bunches from AWS CLI... (6 Replies)
Discussion started by: arun_adm
6 Replies
TDBTOOL(8)																TDBTOOL(8)

NAME
tdbtool - manipulate the contents TDB files SYNOPSIS
tdbtool tdbtool TDBFILE [COMMANDS...] DESCRIPTION
This tool is part of the samba(1) suite. tdbtool a tool for displaying and altering the contents of Samba TDB (Trivial DataBase) files. Each of the commands listed below can be entered interactively or provided on the command line. COMMANDS
create TDBFILE Create a new database named TDBFILE. open TDBFILE Open an existing database named TDBFILE. erase Erase the current database. dump Dump the current database as strings. cdump Dump the current database as connection records. keys Dump the current database keys as strings. hexkeys Dump the current database keys as hex values. info Print summary information about the current database. insert KEY DATA Insert a record into the current database. move KEY TDBFILE Move a record from the current database into TDBFILE. store KEY DATA Store (replace) a record in the current database. show KEY Show a record by key. delete KEY Delete a record by key. list Print the current database hash table and free list. free Print the current database and free list. ! COMMAND Execute the given system command. first Print the first record in the current database. next Print the next record in the current database. quit Exit tdbtool. CAVEATS
The contents of the Samba TDB files are private to the implementation and should not be altered with tdbtool. VERSION
This man page is correct for version 3.0.25 of the Samba suite. AUTHOR
The original Samba software and related utilities were created by Andrew Tridgell. Samba is now developed by the Samba Team as an Open Source project similar to the way the Linux kernel is developed. TDBTOOL(8)
All times are GMT -4. The time now is 04:54 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy