Solved

Need another file split into subfiles

Posted on 2013-11-22
2
207 Views
Last Modified: 2013-11-23
This is along the same line as my last question:     2013-11-15 at 17:33:08 ID28295719

In this case, it is one file that is being split into about 380 files.

Each section to be copied out begins with /*Sec and ends with the line before the next /*Sec.

The file should be named Sec-01-01.sql, Sec-01-02.sql, etc.

/*Sec-01-01:Connecting to a Database*/

USE AdventureWorks2008R2;


/*Sec-01-02:Retrieving Specific Columns*/

SELECT  NationalIDNumber,
        LoginID,
        JobTitle
FROM    HumanResources.Employee;


/*Sec-01-03:Retrieving All Columns*/

SELECT  *
FROM    HumanResources.Employee;


/*Sec-01-04:Specifying Rows to Be Returned*/

SELECT  Title,
        FirstName,
        LastName
FROM    Person.Person
WHERE   Title = 'Ms.';

SELECT  Title, 
        FirstName, 
        LastName
FROM  Person.Person 
WHERE Title = 'Ms.' AND 
        LastName = 'Antrim';

Open in new window

Code-w-Sections.txt
0
Comment
Question by:Alex972
2 Comments
 
LVL 14

Accepted Solution

by:
jb1dev earned 500 total points
ID: 39670805
#!/usr/bin/perl

my $file = $ARGV[0];

if(!defined($file)) {
    print "Specify file name on command line\n";
    exit 1;
}

open FILE, "<$file";

open OUT, ">/dev/null";

while(<FILE>) {
    if(/^\/\*(.*):/) {
        # Found new file 
        # Close previous file.
        close OUT;
        # print "Found section $1\n";
        open OUT, ">$1.sql";
    }
    print OUT $_;
}
close OUT;
close FILE;

Open in new window

0
 

Author Closing Comment

by:Alex972
ID: 39671719
thanks, very good...again
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now