Sponsored Content
Top Forums Shell Programming and Scripting segregate the file based on matching patterns Post 302337095 by mad_man12 on Thursday 23rd of July 2009 11:09:39 AM
Old 07-23-2009
segregate the file based on matching patterns

print 'test'
SETUSER 'dbo'
go
create proc abc
as
/Some code here/
go
SETUSER
go
print 'test1'
SETUSER 'dbo'
go
Create Procedure xyz
as
/some code here/
go
SETUSER
go
print 'test2'
SETUSER 'dbo'
go

now i want to create two files(with the proc names) out of it
abc.txt
xyz.txt


i need to cut the line from the first appeareance of "create" and before the first appeareance of "go"
and name the each file with the procedure name

so the two files will have the data

abc.txt will have
create proc abc
as
/Some code here/

xyz.txt will have
Create Procedure xyz
as
/some code here/

please advise on this issue

---------- Post updated at 10:09 AM ---------- Previous update was at 09:48 AM ----------

i tried
awk '/[cC]reate/,/^go/' a.txt> b.txt

how to replace set b.txt with proc name
and how to eliminate go
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Splitting a file based on two patterns

Hi there, I've an input file as follows: *START 1001 a1 1002 a2 1003 a3 1004 a4 *END *START 1001 b1 1002 b2 1004 b4 *END *START 1001 c1 1004 c4 *END (6 Replies)
Discussion started by: kbirde
6 Replies

2. Shell Programming and Scripting

shell script to format file based on specific patterns

Please help me out and drag me out the deadlock I am stuck into: I have a file. I want the statements under a if...then condition be listed in a separate file in the manner condition|statement.Following are the different input pattern and corresponding output parameters.any generic code to... (7 Replies)
Discussion started by: joyan321
7 Replies

3. Shell Programming and Scripting

Matching patterns

I have a file name in $f. If $f has "-" at the beginning, or "=", or does not have extension ".ry" or ".xt" or ".dat" then cerr would not be empty. Tried the following but having some problems. set cerr = `echo $f | awk '/^-|=|!.ry|!.xt|!.dat/'` (4 Replies)
Discussion started by: kristinu
4 Replies

4. UNIX for Dummies Questions & Answers

Search and extract matching patterns

%%%%% (9 Replies)
Discussion started by: lucasvs
9 Replies

5. Shell Programming and Scripting

Insert value of column based on file name matching

At the top of the XYZ file, I need to insert the ABC data value of column 2 only when ABC column 1 matches the prefix XYZ file name (not the ".txt"). Is there an awk solution for this? ABC Data 0101 0.54 0102 0.48 0103 1.63 XYZ File Name 0101.txt 0102.txt 0103.txt ... (7 Replies)
Discussion started by: ncwxpanther
7 Replies

6. UNIX for Dummies Questions & Answers

File merging based on column patterns

Hello :) I am in this situation: Input: two tab-delimited files, `File1` and `File2`. `File2` (`$2`) has to be parsed by patterns found in `File1` (`$1`). Expected output: tab-delimited file, `File3`. `File3` has to contain the same rows as `File2`, plus the corresponding value in... (5 Replies)
Discussion started by: dovah
5 Replies

7. Shell Programming and Scripting

Segregate files based on the time they are created

Hi All, I have scenario where I need to zip huge number of DB audit log files newer than 90 days and delete anything older than that. If the files are too huge in number,zipping will take long time and causing CPU spikes. To avoid this I wanted to segregate files based on how old they are and... (2 Replies)
Discussion started by: veeresh_15
2 Replies

8. Shell Programming and Scripting

Help with tag value extraction from xml file based on a matching condition

Hi , I have a situation where I need to search an xml file for the presence of a tag <FollowOnFrom> and also , presence of partial part of the following tag <ContractRequest _LoadId and if these 2 exist ,then extract the value from the following tag <_LocalId> which is "CW2094139". There... (2 Replies)
Discussion started by: paul1234
2 Replies

9. Shell Programming and Scripting

Delete patterns matching

Delete patterns matching OS version: RHEL 7.3 Shell : Bash I have a file like below (pattern.txt). I need to delete all lines starting with the following words (words separated by comma below) and ) character. LOGGING, NOCOMPRESS, TABLESPACE , PCTFREE, INITRANS, MAXTRANS, STORAGE,... (3 Replies)
Discussion started by: John K
3 Replies

10. Shell Programming and Scripting

How to segregate a section from big file?

Hello, I need to know all IP range (ip_prefix), associated with us-west-2 region only from this link - https://ip-ranges.amazonaws.com/ip-ranges.json (it can be opened in wordpad for better visibility) Please suggest, how would I do it. If vi, awk or sed is needed, I have downloaded it on my... (7 Replies)
Discussion started by: solaris_1977
7 Replies
RoPkg::DBObject(3pm)					User Contributed Perl Documentation				      RoPkg::DBObject(3pm)

NAME
RoPkg::DBObject - General pourpose database object. VERSION
0.1.4 DESCRIPTION
This class can be used as a base class for objects who holds all their information in a database. The class provides the base methods to add/delete/update/select the object to/from a database. RoPkg::DBObject inherits RoPkg::Object . SYNOPSIS
package RoPkg::Person; use strict; use warnings; use RoPkg::DBObject; use RoPkg::Exceptions; use vars qw($VERSION @ISA); @ISA=qw(RoPkg::DBObject); my $methods = { id => '-', Name => '-', Addr => '-', }; sub new { my ($class, %opt) = @_; my $self; $opt{methods} = $methods; $self = $class->SUPER::new(%opt); return $self; } sub AddToDB { my ($self) = @_; OutsideClass->throw('Called from outside class') if ( !$self or ref($self) ne $CLASS); return $self->SQL_Insert(); } 1; tester.pl use warnings; use strict; use RoPkg::Person; use RoPkg::DB; sub main { my ($p, $db); $db = new RoPkg::DB(); $db->add('dsn...', 'user', 'pass', 'dbc'); $p = new RoPkg::Person(dbo => $db, dbo_method => 'db_dbc'); $p->id(1); $p->Name('John Doe'); $p->Addr('home'); $p->AddToDB(); } main(); SUBROUTINES
/METHODS new($hashref) Constructor of the class. At this moment new() accepts 3 parameters: *) dbo *) dbo_method *) quote_char dbo and dbo_method must be given to the constructor. quote_char is optional. dbo is the database object (a instance of RoPkg::DB)and dbo_method dbo_method is the name of the method used to have access to the database handle. quote_char is the char used internally by DBI to quote the table names, field names and so on. Default, the quote_char is empty (no quotation). If you are using PostgreSQL and you have upcase chars in table and fields names use quote_char => q{"} . Exceptions: RoPkg::DBObject uses the exceptions provided by RoPkg::Exceptions. new() throws the following exceptions: *) Param::Mising *) Param::Wrong Param::Missing is raised when dbo or dbo_method parameters have not been specified in the parameters list. Param::Wrong is raised when dbo or dbo_method parameters are not defined (or empty). dbo($dbo) get/set method. If $dbo is present (and defined), the internal $dbo object will be replaced with the new one. If $dbo is not present, the method acts as a get method, and will return the database object. The method will raise OutsideClass exception if is called outside the class instance. dbo_method($dbo_method) get/set method. If $dbo_method is present (and defined), the internal $dbo_method value will be replaced with the one specified by $dbo_method parameter. Otherwise, the get behaviour will be selected, and the method will return the current value of $dbo_method. The method will raise OutsideClass exception if is called outside the class instance. dbh() Returns the DBI object used by this object. SQL METHODS
The following methods are responsable for all operations involving the database. All methods use SQL::Abstract to generate sql queries to ensure portability of the queries. The data that will be added/deleted to the database, is taken from the methods provided by $methods . SQL_Insert() add the current object to the database. Returns the value of DBI->execute. SQL_Update(@fields) update the data from database. The fields array hold all the field names who will uniquely identify the object in the database (usually the id of the object). SQL_Delete(@fields) update the data from database. The fields array hold all the field names who will uniquely identify the object in the database (usually the id of the object). SQL_Select(@fields) searches into the database for the object and initialize the current object with the values found. The fields array hold all the field names who will uniquely identify the object in the database (usually the id of the object). This method is special. It will look only at the first record who meet the requirements (in sql 'LIMIT 1'). Also, if no records are found DB::NoResults exception is raised. DEPENDENCIES
RoPkg::Object require perl 5.008 or later and the following modules: SQL::Abstract RoPkg::Object RoPkg::Exceptions PERL CRITIC
The code is perl critic level 2 compliant and almost level 1 compliant DIAGNOSTICS
This module comes with his own tests. To run the tests unpack the source, and use 'make test' command. CONFIGURATION AND ENVIRONMENT
This module does not use any configuration files or environment variables. The dependencies however can use them. Please read the man page of each dependency to be sure. INCOMPATIBILITIES
Do not install this version on the same machine with Simba <= 0.7.1 BUGS AND LIMITATIONS
None known to the author AUTHOR
Subredu Manuel <diablo@iasi.roedu.net> LICENSE AND COPYRIGHT
Copyright (C) 2005 Subredu Manuel. All Rights Reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The LICENSE file contains the full text of the license. perl v5.8.8 2006-06-09 RoPkg::DBObject(3pm)
All times are GMT -4. The time now is 04:10 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy