Sponsored Content
Top Forums Shell Programming and Scripting sql dump file - how to get certain values using sed Post 302638215 by ashokvpp on Thursday 10th of May 2012 03:47:54 AM
Old 05-10-2012
sql dump file - how to get certain values using sed

Hi,

I have a dumpfile.sql -
========Start of file=================
Code:
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `mysql` /*!40100 DEFAULT CHARACTER SET latin1 */;

CREATE TABLE  `test_table1` (
  `id` int 
) AUTO_INCREMENT=12
CREATE TABLE  `test_table2` (
  `id` int 
) AUTO_INCREMENT=120
CREATE TABLE  `test_table3` (
  `id` int 
) AUTO_INCREMENT=1200

CREATE DATABASE /*!32312 IF NOT EXISTS*/ `sample` /*!40100 DEFAULT CHARACTER SET latin1 */;

 CREATE TABLE  `sample_table1` (
  `id` int 
) AUTO_INCREMENT=12
CREATE TABLE  `sample_table2` (
   `id` int 
 ) AUTO_INCREMENT=120
CREATE TABLE  `sample_table3` (
   `id` int 
 ) AUTO_INCREMENT=1200

==============eof======================

I need the output as: i,e
Code:
test,test_table1,AUTO_INCREMENT=12
test,test_table2,AUTO_INCREMENT=120
test,test_table3,AUTO_INCREMENT=1200
sample,sam_table1,AUTO_INCREMENT=12
sample,sam_table2,AUTO_INCREMENT=120
sample,sam_table3,AUTO_INCREMENT=1200

I tried with basic sed - given in this forum but still unable to get the desired output.

I am not sure if I need to use awk as well.

Please post the best way to achieve this.

Thank you.

Moderator's Comments:
Mod Comment How to use code tags

Last edited by Franklin52; 05-10-2012 at 04:52 AM.. Reason: Please use code tags
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Aggregate values in a file & compare with sql output

Hi, I have a file containing the following data: junk123junk723itemcode001qty01price10total10junkjunk junk123junk723itemcode002qty02price10total20junkjunk .. .. .. could be 5000+ lines I have an algo and need a code to implement this: 1. Linecount = wc -l (should give 5000) 2. For i... (1 Reply)
Discussion started by: shiroh_1982
1 Replies

2. Shell Programming and Scripting

use SQL loader to dump a fixed length file in to DB

consider a fixed length file 12345abcd8901 12345abcd7777 12345njdu8888 12345hdku8388 i would like to dump it in to oracle DB using sql loader 12345 in to first coloumn abcd in to second coloumn 8901 in to 3rd coloumn (2 Replies)
Discussion started by: anumkoshy
2 Replies

3. Shell Programming and Scripting

SED + Regex + SQL Input file

Here's the problem... I have a mysqldump file and I need to put single quotes around the date/time timestamp. So for example I have a line like: INSERT INTO attachments VALUES (1,182,2004-08-06 09:24:04,'description'... and I need it to become INSERT INTO attachments VALUES... (10 Replies)
Discussion started by: primal
10 Replies

4. Shell Programming and Scripting

how to break mysql dump sql file

Hi folks I have mysql dump which having insert queries, i want to break that file when 10 complete "INSERTS" lines so extract that line and store in 1.sql and 2.sql and for next 10 insert lines. pls guide me how can i do that. Regards, Bash (2 Replies)
Discussion started by: learnbash
2 Replies

5. Shell Programming and Scripting

Reading values from a file using DB2 SQL

I have some alphbetical codes in that (1 Reply)
Discussion started by: kavithakuttyk
1 Replies

6. Shell Programming and Scripting

How do i use sed to replace string with values from a dictionary file

I have file 1 with one million rows. one of the fields is "FIRSTNAME" (the string) I have a second file with about 20 first names. JUDE DAVID HOMER CANE ABEL MARTY CARL SONNY STEVE BERT OSCAR MICKY JAMES JOHN GLENN DOUG (3 Replies)
Discussion started by: yoyolandre
3 Replies

7. Shell Programming and Scripting

formating sql file using awk or sed

Hi, I have a file where I would like to add a prompt type object_name statement before every create commnad create or replace force view test_view_01 ( col1 col2 col3 ) as (select a,b,c from sometable ); create or replace view test_view_02 ( col4 col5 col6 ) as (5 Replies)
Discussion started by: jville
5 Replies

8. Shell Programming and Scripting

sed parse a lign into a new sql file

Hi everyone, another question while using sed. my sed statement should parse every line in a file and store all "i" variable item a a new file. any wrong arguments here? Thanks a million. task_name => name, object_type => 'TABLE', attr1 => 'TestR3', attr2 => '$i', for i... (4 Replies)
Discussion started by: sundaygeek
4 Replies

9. Programming

create a spool file based on values passed from korn shell to sql script

this is my issue. 4 parameters are passed from korn shell to sql script. parameter_1= varchar2 datatype or no value entered my user. parameter_2= number datatype or no value entered my user. parameter_3= number datatype or no value entered my user. parameter_4= number datatype or no... (5 Replies)
Discussion started by: megha2525
5 Replies

10. Shell Programming and Scripting

Links replacement on sql dump

Hi All I have dump of mysql DB (Joomla), and I found out that there is absolute links on the DB not with the domain name but the IP address ex: ,(115205,'http://54.5.17.148//index.php/restoflink... (12 Replies)
Discussion started by: molwiko
12 Replies
ALTER 
VIEW(7) PostgreSQL 9.2.7 Documentation ALTER VIEW(7) NAME
ALTER_VIEW - change the definition of a view SYNOPSIS
ALTER VIEW [ IF EXISTS ] name ALTER [ COLUMN ] column_name SET DEFAULT expression ALTER VIEW [ IF EXISTS ] name ALTER [ COLUMN ] column_name DROP DEFAULT ALTER VIEW [ IF EXISTS ] name OWNER TO new_owner ALTER VIEW [ IF EXISTS ] name RENAME TO new_name ALTER VIEW [ IF EXISTS ] name SET SCHEMA new_schema ALTER VIEW [ IF EXISTS ] name SET ( view_option_name [= view_option_value] [, ... ] ) ALTER VIEW [ IF EXISTS ] name RESET ( view_option_name [, ... ] ) DESCRIPTION
ALTER VIEW changes various auxiliary properties of a view. (If you want to modify the view's defining query, use CREATE OR REPLACE VIEW.) You must own the view to use ALTER VIEW. To change a view's schema, you must also have CREATE privilege on the new schema. To alter the owner, you must also be a direct or indirect member of the new owning role, and that role must have CREATE privilege on the view's schema. (These restrictions enforce that altering the owner doesn't do anything you couldn't do by dropping and recreating the view. However, a superuser can alter ownership of any view anyway.) PARAMETERS
name The name (optionally schema-qualified) of an existing view. IF EXISTS Do not throw an error if the view does not exist. A notice is issued in this case. SET/DROP DEFAULT These forms set or remove the default value for a column. A default value associated with a view column is inserted into INSERT statements on the view before the view's ON INSERT rule is applied, if the INSERT does not specify a value for the column. new_owner The user name of the new owner of the view. new_name The new name for the view. new_schema The new schema for the view. view_option_name The name of a view option to be set or reset. view_option_value The new value for a view option. NOTES
For historical reasons, ALTER TABLE can be used with views too; but the only variants of ALTER TABLE that are allowed with views are equivalent to the ones shown above. EXAMPLES
To rename the view foo to bar: ALTER VIEW foo RENAME TO bar; COMPATIBILITY
ALTER VIEW is a PostgreSQL extension of the SQL standard. SEE ALSO
CREATE VIEW (CREATE_VIEW(7)), DROP VIEW (DROP_VIEW(7)) PostgreSQL 9.2.7 2014-02-17 ALTER VIEW(7)
All times are GMT -4. The time now is 07:25 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy