Help splitting file

Please support our Perl advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Feb 2009
Posts: 3
Reputation: pharitha is an unknown quantity at this point 
Solved Threads: 0
pharitha pharitha is offline Offline
Newbie Poster

Help splitting file

 
0
  #1
Feb 12th, 2009
Could anyone help me splitting a big file into subfiles. The file is something similar to this:

1.SYSTEM = UNIX
2.variable = value

3.>ACTIVATED 1

4.ALL: FILE1
5.ALL:FILE2
6.ALL:FILE3
7.ALL:FILE4

8.>ACTIVATED 1
9. ################*
10.>>CONDITIONS
11.################

12.MODEL:
13.<one ExeSimpleName> : <one or more Flags> : [Options]

I need to split this file into many files such that first file has only one ALL:FILE1 and second has ALL:FILE2 and third has only ALL: FILE3 and fourth ALL:FILE4

The remaining contents should be the same. Can anyone please give me an idea of doing it in perl...

Immediate help would be appreciated as I am struggling with this from few days.

Thanks
Hari.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 898
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 67
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: Help splitting file

 
0
  #2
Feb 12th, 2009
Since this will be very dependent on the exact data in the file there is little sense in trying to help with data that is something similar to the real data.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3
Reputation: pharitha is an unknown quantity at this point 
Solved Threads: 0
pharitha pharitha is offline Offline
Newbie Poster

Re: Help splitting file

 
0
  #3
Feb 12th, 2009
I just need the logic of doing it .The real data is very close to the data which i gave.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Help splitting file

 
0
  #4
Feb 12th, 2009
when you say "the remaining contents should be the same" do you mean, in file1 (ALL:FILE1) it should have just ALL:FILE1, AND the rest of the file (with the exception of ALL:FILE2, and ALL:FILE3, etc) or .... what?
Last edited by Comatose; Feb 12th, 2009 at 10:55 am.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 898
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 67
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: Help splitting file

 
1
  #5
Feb 12th, 2009
Originally Posted by pharitha View Post
I just need the logic of doing it .The real data is very close to the data which i gave.
Use a regular expression and a counter.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3
Reputation: pharitha is an unknown quantity at this point 
Solved Threads: 0
pharitha pharitha is offline Offline
Newbie Poster

Re: Help splitting file

 
0
  #6
Feb 13th, 2009
If i think the file which i gave is "file x" then the files after split say filex1 should contain :

1.SYSTEM = UNIX
2.variable = value

3.>ACTIVATED 1

4.ALL: FILE1

5.>ACTIVATED 1
6. ################*
7.>>CONDITIONS
8.################

9.MODEL:
10.<one ExeSimpleName> : <one or more Flags> : [Options]

Let me know if its still not clear for you.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 58
Reputation: mitchems is an unknown quantity at this point 
Solved Threads: 2
mitchems's Avatar
mitchems mitchems is offline Offline
Junior Poster in Training

Re: Help splitting file

 
0
  #7
Feb 13th, 2009
Load the original file into array with push. Go through the array X number of times. Look for each line containing FILEX and skip the ones containing FILEY. Then write out the array to new files. Fairly inefficient, but it will work fine.
And don't tell me there isn't one bit of difference between null and space, because that's exactly how much difference there is.

Larry Wall
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 898
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 67
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: Help splitting file

 
0
  #8
Feb 13th, 2009
He said he wanted the logic but what I suspect he really wants is code. I prefer to write code for people that show effort.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 58
Reputation: mitchems is an unknown quantity at this point 
Solved Threads: 2
mitchems's Avatar
mitchems mitchems is offline Offline
Junior Poster in Training

Re: Help splitting file

 
0
  #9
Feb 13th, 2009
Hey understood. I was GOING to actually write the code... but... I decided to just put in the concept... with no code. I wrote the actual code in my head on my walking to the train today - HOWEVER... I didn't actually write it or post it because of what you mention - haha. BTW like I said my approach is inefficient but it will work perfectly. I don't like multi-nested loops/fors/whiles but in this case it will work fine. I suspect he just has to do this ONCE and if so, effectiveness is more important than efficiency IMO.

I do appreciate your post.

Mike

Originally Posted by KevinADC View Post
He said he wanted the logic but what I suspect he really wants is code. I prefer to write code for people that show effort.
And don't tell me there isn't one bit of difference between null and space, because that's exactly how much difference there is.

Larry Wall
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC