Computing.Net > Forums > Unix > Split File

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Split File

Reply to Message Icon

Name: nimi
Date: July 12, 2006 at 23:58:39 Pacific
OS: Unix
CPU/Ram: NA
Product: NA
Comment:

Hi,

I have a text file which contains the following information.

'DISP SPGTRUL' EXECUTING
---------
SPGTTRL | SPGTRUL | Global Title | SPGTCRUL | Pointer
---------
ID | Name | ID | Name | Address Information | ID | Name | Type | ID | Name
=============================================================================================================================
2 | INTINT | 0 | ------------ | 60120000215 | - | - | SPRNS | 16 | SMS015
---------
2 | INTINT | 1 | 963 | 963 | - | - | SPRNS | 55 | IRIGLS
---------
2 | INTINT | 2 | 595 | 595 | - | - | SPRNS | 55 | IRIGLS
---------
2 | INTINT | 3 | 60120001035 | 60120001035 | - | - | SPRNS | 26 | IN3#3
---------
.
.
.
---------
2 | INTINT | 499 | 6012202 | 6012202 | 1 | CANGT | SPENS | 10 | HLHTA

TABLE 1/2

--
SPGTTRL | SPGTRUL | Global Title | Include | Possible | Traffic | Resume
--
ID | Name | ID | Name | Address Information | SPC | Ported Number | Type | At Digit
======================================================================================================================
2 | INTINT | 0 | ------------ | 60120000215 | FALSE | FALSE | Nat. Own | -
--
2 | INTINT | 1 | 963 | 963 | FALSE | FALSE | Nat. Own | -
--
2 | INTINT | 2 | 595 | 595 | FALSE | FALSE | Nat. Own | -
--
2 | INTINT | 3 | 60120001035 | 60120001035 | FALSE | FALSE | Nat. Own | -
--
.
.
.
--
2 | INTINT | 499 | 6012202 | 6012202 | FALSE | FALSE | Nat. Own | -

TABLE 2/2


Work in progress...

'DISP SPGTRUL' EXECUTING
---------
SPGTTRL | SPGTRUL | Global Title | SPGTCRUL | Pointer
---------
ID | Name | ID | Name | Address Information | ID | Name | Type | ID | Name
=============================================================================================================================
2 | INTINT | 500 | 6012203 | 6012203 | 1 | CANGT | SPENS | 10 | HLHTA
---------
2 | INTINT | 501 | 6012200 | 6012200 | 10 | INTINTB | SPGTTRL | 1 | INTNAT
---------
2 | INTINT | 502 | 6012205 | 6012205 | 1 | CANGT | SPENS | 10 | HLHTA
---------
2 | INTINT | 503 | 6012206 | 6012206 | 1 | CANGT | SPENS | 10 | HLHTA
---------
.
.
.
---------
2 | INTINT | 999 | 6012270 | 6012270 | 1 | CANGT | SPENS | 128 | HLNLB

TABLE 1/2

--
SPGTTRL | SPGTRUL | Global Title | Include | Possible | Traffic | Resume
--
ID | Name | ID | Name | Address Information | SPC | Ported Number | Type | At Digit
======================================================================================================================
2 | INTINT | 500 | 6012203 | 6012203 | FALSE | FALSE | Nat. Own | -
--
2 | INTINT | 501 | 6012200 | 6012200 | FALSE | FALSE | Nat. Own | 1
--
2 | INTINT | 502 | 6012205 | 6012205 | FALSE | FALSE | Nat. Own | -
--
2 | INTINT | 503 | 6012206 | 6012206 | FALSE | FALSE | Nat. Own | -
--
.
.
.
--
2 | INTINT | 999 | 6012270 | 6012270 | FALSE | FALSE | Nat. Own | -

TABLE 2/2


Work in progress...

'DISP SPGTRUL' EXECUTING

and the file goes on

Now, I have to merge all records in Table 1 into a file and all records in Table 2 to another file.

How do I do that?

Nimi



Sponsored Link
Ads by Google

Response Number 1
Name: nimi
Date: July 13, 2006 at 18:24:41 Pacific
Reply:

My Perl script is:-

#!/usr/bin/perl

$strMain_Dir = "/data/Dstage/SDCT/source";
$strSubA_Dir = "/data/Dstage/SDCT/output";
$strSubB_Dir = "/data/Dstage/SDCT/output";


opendir DIRHANDLE, $strMain_Dir;

@strFiles = grep !/^\.\.?$/, readdir DIRHANDLE;
closedir DIRHANDLE;


$iFileCount = 0;

while ($strFiles[$iFileCount] ne "")
{
print "Processing $strFiles[$iFileCount], please wait\n";
Process_File ("$strFiles[$iFileCount]");
$iFileCount++;
}

sub Process_File {
local ($strFile) = @_;

#Get the Out File Name
$strOutFileA = "$strSubA_Dir/$strFile".".subA";
$strOutFileB = "$strSubB_Dir/$strFile".".subB";
open (IFILE, "$strMain_Dir/$strFile");
open (OUTFILEA, ">$strOutFileA");
open (OUTFILEB, ">$strOutFileB");

$iCounter = 0;
while (<IFILE>)
{
$strLine = $_;
$strHeader = substr ($strLine,0,7);

if ($strHeader eq "TABLE 1")
{
$iCounter++;

}

if ($strHeader eq "TABLE 2")
{
$iCounter = 0;
}

if ($iCounter = 0)
{
print OUTFILEA ($strLine);
}
else
{
print OUTFILEB ($strLine);
}
}

close (IFILE);
close (OUTFILEA);
close (OUTFILEB);

}


I am not getting the desired result. What went wrong?

Nimi


0

Response Number 2
Name: nimi
Date: July 13, 2006 at 20:07:58 Pacific
Reply:

its ok i found the solution.

Nimi


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Split File

ftp large file .gzip www.computing.net/answers/unix/ftp-large-file-gzip/5549.html

splitting fileds into rows in unix www.computing.net/answers/unix/splitting-fileds-into-rows-in-unix/7868.html

How to enable faster downloads from www.computing.net/answers/unix/how-to-enable-faster-downloads-from/5948.html