Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Need another file split into subfiles

Posted on 2013-11-22
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,
FROM    HumanResources.Employee;

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

FROM    HumanResources.Employee;

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

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

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

Open in new window

Question by:Alex972
LVL 14

Accepted Solution

jb1dev earned 500 total points
ID: 39670805

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


Author Closing Comment

ID: 39671719
thanks, very good...again

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Sending email via Perl on Windows 3 182
how to extract data from a table into a fixed length file 10 59
perl search and replace 6 171
perl: Cleaning meta tags using RegEX 12 82
I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…

789 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