| | |
Help splitting file
Please support our Perl advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Feb 2009
Posts: 3
Reputation:
Solved Threads: 0
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.
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.
•
•
Join Date: Feb 2009
Posts: 3
Reputation:
Solved Threads: 0
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.
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.
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
Larry Wall
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
I do appreciate your post.
Mike
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
Larry Wall
![]() |
Similar Threads
- Splitting of wav files (C#)
- File Upload Help (PHP)
- conversion of text file into data base file (Visual Basic 4 / 5 / 6)
- get werid error when splitting up my code (C++)
- Splitting Files ., Making them fit to a CD (Windows NT / 2000 / XP)
- Splitting a program into different classes. (Java)
Other Threads in the Perl Forum
- Previous Thread: OLE and Office 2007
- Next Thread: Print in Perl
Views: 788 | Replies: 8
| Thread Tools | Search this Thread |
Tag cloud for Perl






