Sponsored Content
Top Forums UNIX for Dummies Questions & Answers split a single sql file into multiple files Post 302235656 by rubin on Friday 12th of September 2008 11:12:12 AM
Old 09-12-2008
If the blank line between CREATE TABLE paragraphs is always present this should suffice:

Code:
awk '/CREATE TABLE/{ n++; print > (f="out_" n); close(f)}' RS=  sql_file

Otherwise use,

Code:
awk '/CREATE TABLE/{f=0 ;n++; print >(file="out_" n); close("out_" n-1)} f{ print > file}; /CREATE TABLE/{f=1}'  sql_file

This User Gave Thanks to rubin For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Executing Multiple .SQL Files from Single Shell Script file

Hi, Please help me out. I have around 700 sql files to execute in a defined order, how can i do it from shell script (3 Replies)
Discussion started by: anushilrai
3 Replies

2. Shell Programming and Scripting

Split a file into multiple files

I have a file ehich has multiple create statements as create abc 123 one two create xyz 456 four five create nnn 666 six four I want to separte each create statement in seperate files (3 Replies)
Discussion started by: glamo_2312
3 Replies

3. Programming

Single sql query to spool to multiple files

Is there anyway to spool my select statement into spool files of max 10000 records each? eg I have a select statement that will return 45000 records. A normal spool command will output the 45000 into just one spool file. How can I make sqlplus do this? 00001 - 10000 records --- spool... (3 Replies)
Discussion started by: Leion
3 Replies

4. Shell Programming and Scripting

Split single file into multiple files based on the number in the column

Dear All, I would like to split a file of the following format into multiple files based on the number in the 6th column (numbers 1, 2, 3...): ATOM 1 N GLY A 1 -3.198 27.537 -5.958 1.00 0.00 N ATOM 2 CA GLY A 1 -2.199 28.399 -6.617 1.00 0.00 ... (3 Replies)
Discussion started by: tomasl
3 Replies

5. Shell Programming and Scripting

Split the single file lines into multiple files

Let's assume that I have a file name called ‘A' and it has 100 lines in it and would like to split these 100 lines into 4 files as specified bellow. INPUT: Input file name A 1 2 3 4 5 6 7 8 9 ........100 Output: 4 output files (x,y,z,w) File x should contains (Skip 4 lines)... (15 Replies)
Discussion started by: subbarao25
15 Replies

6. Shell Programming and Scripting

Execute multiple SQL scripts from single SQL Plus connection

Hi! I would like to do a single connection to sqlplus and execute some querys. Actually I do for every query one connection to database i.e echo 'select STATUS from v$instance; exit' > $SQL_FILE sqlplus user/pass@sid @$SQL_FILE > $SELECT_RESULT echo 'select VERSION from v$instance;... (6 Replies)
Discussion started by: guif
6 Replies

7. UNIX for Dummies Questions & Answers

Split single file into n number of files

Hi, I am new to unix. we have a requirement here to split a single file into multiples files based on the number of people available for processing. So i tried my hand at writing some code as below. #!/bin/bash var1=`wc -l $filename` var2=$var1/$splitno split -l $var2 $1 Please help me... (6 Replies)
Discussion started by: quirkguy
6 Replies

8. Shell Programming and Scripting

Split single file into multiple files using pattern matching

I have one single shown below and I need to break each ST|850 & SE to separate file using unix script. Below example should create 3 files. We can use ST & SE to filter as these field names will remain same. Please advice with the unix code. ST|850 BEG|PO|1234 LIN|1|23 SE|4 ST|850... (3 Replies)
Discussion started by: prasadm
3 Replies

9. UNIX for Dummies Questions & Answers

Split files into smaller ones with 1000 hierarchies in a single file.

input file: AD,00,--,---,---,---,---,---,---,--,--,--- AM,000,---,---,---,---,---,--- AR, ,---,--,---,--- AA,---,---,---,--- AT,--- AU,---,---,--- AS,---,--- AP,---,---,--- AI,--- AD,00,---,---,---, ,---,---,---,---,---,--- AM,000,---,---,--- AR,... (6 Replies)
Discussion started by: kcdg859
6 Replies

10. Shell Programming and Scripting

Split a single file into multiple files based on a value.

Hi All, I have the sales_data.csv file in the directory as below. SDDCCR; SOM ; MD6546474777 ;05-JAN-16 ABC ; KIRAN ; CB789 ;04-JAN-16 ABC ; RAMANA; KS566767477747 ;06-JAN-16 ABC ; KAMESH; A33535335 ;04-JAN-16 SDDCCR; DINESH; GD6674474747 ;08-JAN-16... (4 Replies)
Discussion started by: ROCK_PLSQL
4 Replies
GAMMU-SMSD-DBI(7)						       Gammu							 GAMMU-SMSD-DBI(7)

NAME
gammu-smsd-dbi - gammu-smsd(1) backend using DBI abstraction layer to use any supported database as a message storage DESCRIPTION
DBI backend stores all data in any database supported by libdbi, which parameters are defined by configuration (see gammu-smsdrc for description of configuration options). For tables description see gammu-smsd-tables. This backend is based on gammu-smsd-sql. Note The DBI driver is currently not supported on Windows because libdbi library does not support this platform. CONFIGURATION
Before running gammu-smsd you need to create necessary tables in the database. You can use examples given in database specific backends parts of this manual to do that. The configuration file then can look like: [smsd] service = sql driver = DBI_DRIVER host = localhost See also gammu-smsdrc SUPPORTED DRIVERS
For complete list of drivers for libdbi see libdbi-drivers project. The drivers for example include: o sqlite3 - for SQLite 3 o mysql - for MySQL o pgsql - for PostgeSQL o freetds - for MS SQL Server or Sybase CREATING TABLES
SQL script for creating tables in SQLite database: CREATE TABLE daemons ( Start TEXT NOT NULL, Info TEXT NOT NULL ); CREATE TABLE gammu ( Version INTEGER NOT NULL DEFAULT '0' ); INSERT INTO gammu (Version) VALUES (13); CREATE TABLE inbox ( UpdatedInDB NUMERIC NOT NULL DEFAULT (datetime('now')), ReceivingDateTime NUMERIC NOT NULL DEFAULT (datetime('now')), Text TEXT NOT NULL, SenderNumber TEXT NOT NULL DEFAULT '', Coding TEXT NOT NULL DEFAULT 'Default_No_Compression', UDH TEXT NOT NULL, SMSCNumber TEXT NOT NULL DEFAULT '', Class INTEGER NOT NULL DEFAULT '-1', TextDecoded TEXT NOT NULL DEFAULT '', ID INTEGER PRIMARY KEY AUTOINCREMENT, RecipientID TEXT NOT NULL, Processed TEXT NOT NULL DEFAULT 'false', CHECK (Coding IN ('Default_No_Compression','Unicode_No_Compression','8bit','Default_Compression','Unicode_Compression')) ); CREATE TRIGGER update_inbox_time UPDATE ON inbox BEGIN UPDATE inbox SET UpdatedInDB = datetime('now') WHERE ID = old.ID; END; CREATE TABLE outbox ( UpdatedInDB NUMERIC NOT NULL DEFAULT (datetime('now')), InsertIntoDB NUMERIC NOT NULL DEFAULT (datetime('now')), SendingDateTime NUMERIC NOT NULL DEFAULT (datetime('now')), SendBefore time NOT NULL DEFAULT '23:59:59', SendAfter time NOT NULL DEFAULT '00:00:00', Text TEXT, DestinationNumber TEXT NOT NULL DEFAULT '', Coding TEXT NOT NULL DEFAULT 'Default_No_Compression', UDH TEXT, Class INTEGER DEFAULT '-1', TextDecoded TEXT NOT NULL DEFAULT '', ID INTEGER PRIMARY KEY AUTOINCREMENT, MultiPart TEXT NOT NULL DEFAULT 'false', RelativeValidity INTEGER DEFAULT '-1', SenderID TEXT, SendingTimeOut NUMERIC NOT NULL DEFAULT (datetime('now')), DeliveryReport TEXT DEFAULT 'default', CreatorID TEXT NOT NULL, CHECK (Coding IN ('Default_No_Compression','Unicode_No_Compression','8bit','Default_Compression','Unicode_Compression')), CHECK (DeliveryReport IN ('default','yes','no')) ); CREATE INDEX outbox_date ON outbox(SendingDateTime, SendingTimeOut); CREATE INDEX outbox_sender ON outbox(SenderID); CREATE TRIGGER update_outbox_time UPDATE ON outbox BEGIN UPDATE outbox SET UpdatedInDB = datetime('now') WHERE ID = old.ID; END; CREATE TABLE outbox_multipart ( Text TEXT, Coding TEXT NOT NULL DEFAULT 'Default_No_Compression', UDH TEXT, Class INTEGER DEFAULT '-1', TextDecoded TEXT DEFAULT NULL, ID INTEGER, SequencePosition INTEGER NOT NULL DEFAULT '1', CHECK (Coding IN ('Default_No_Compression','Unicode_No_Compression','8bit','Default_Compression','Unicode_Compression')), PRIMARY KEY (ID, SequencePosition) ); CREATE TABLE pbk ( ID INTEGER PRIMARY KEY AUTOINCREMENT, GroupID INTEGER NOT NULL DEFAULT '-1', Name TEXT NOT NULL, Number TEXT NOT NULL ); CREATE TABLE pbk_groups ( Name TEXT NOT NULL, ID INTEGER PRIMARY KEY AUTOINCREMENT ); CREATE TABLE phones ( ID TEXT NOT NULL, UpdatedInDB NUMERIC NOT NULL DEFAULT (datetime('now')), InsertIntoDB NUMERIC NOT NULL DEFAULT (datetime('now')), TimeOut NUMERIC NOT NULL DEFAULT (datetime('now')), Send TEXT NOT NULL DEFAULT 'no', Receive TEXT NOT NULL DEFAULT 'no', IMEI TEXT PRIMARY KEY NOT NULL, Client TEXT NOT NULL, Battery INTEGER NOT NULL DEFAULT -1, Signal INTEGER NOT NULL DEFAULT -1, Sent INTEGER NOT NULL DEFAULT 0, Received INTEGER NOT NULL DEFAULT 0 ); CREATE TRIGGER update_phones_time UPDATE ON phones BEGIN UPDATE phones SET UpdatedInDB = datetime('now') WHERE IMEI = old.IMEI; END; CREATE TABLE sentitems ( UpdatedInDB NUMERIC NOT NULL DEFAULT (datetime('now')), InsertIntoDB NUMERIC NOT NULL DEFAULT (datetime('now')), SendingDateTime NUMERIC NOT NULL DEFAULT (datetime('now')), DeliveryDateTime NUMERIC NULL, Text TEXT NOT NULL, DestinationNumber TEXT NOT NULL DEFAULT '', Coding TEXT NOT NULL DEFAULT 'Default_No_Compression', UDH TEXT NOT NULL, SMSCNumber TEXT NOT NULL DEFAULT '', Class INTEGER NOT NULL DEFAULT '-1', TextDecoded TEXT NOT NULL DEFAULT '', ID INTEGER, SenderID TEXT NOT NULL, SequencePosition INTEGER NOT NULL DEFAULT '1', Status TEXT NOT NULL DEFAULT 'SendingOK', StatusError INTEGER NOT NULL DEFAULT '-1', TPMR INTEGER NOT NULL DEFAULT '-1', RelativeValidity INTEGER NOT NULL DEFAULT '-1', CreatorID TEXT NOT NULL, CHECK (Status IN ('SendingOK','SendingOKNoReport','SendingError','DeliveryOK','DeliveryFailed','DeliveryPending', 'DeliveryUnknown','Error')), CHECK (Coding IN ('Default_No_Compression','Unicode_No_Compression','8bit','Default_Compression','Unicode_Compression')) , PRIMARY KEY (ID, SequencePosition) ); CREATE INDEX sentitems_date ON sentitems(DeliveryDateTime); CREATE INDEX sentitems_tpmr ON sentitems(TPMR); CREATE INDEX sentitems_dest ON sentitems(DestinationNumber); CREATE INDEX sentitems_sender ON sentitems(SenderID); CREATE TRIGGER update_sentitems_time UPDATE ON sentitems BEGIN UPDATE sentitems SET UpdatedInDB = datetime('now') WHERE ID = old.ID; END; Note You can find the script in docs/sql/sqlite.sql as well. There are also scripts for other databases in same folder. UPGRADING TABLES
The easiest way to upgrade database structure is to backup old one and start with creating new one based on example above. For upgrading existing database, you can use changes described in smsd-tables-history and then manually update Version field in gammu ta- ble. AUTHOR
Michal iha <michal@cihar.com> COPYRIGHT
2009-2012, Michal iha <michal@cihar.com> 1.31.90 February 24, 2012 GAMMU-SMSD-DBI(7)
All times are GMT -4. The time now is 05:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy