|
google site
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
![]() |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Split a file based on a pattern
Dear all, I have a large file which is composed of 8000 frames, what i would like to do is split the file into 8000 single files names file.pdb.1, file.pdb.2 etc etc each frame in the large file is seperated by a "ENDMDL" flag so my thinking is to use this flag a a point to split the files up. however im having great dificulty in trying to output each frame to a new file in perl? suggetsions and help will be much appreciated. example of the large file Code:
ENDMDL mpla mpla ok ok ,pla mpla mpla mpla mpla ENDMDL mpla2 mpla2 mpla2 mpla2 mpla2 mpla2 mpla2 mpla2 ENDMDL mpla mpla ok ok ,pla mpla mpla mpla mpla ENDMDL mpla2 mpla2 mpla2 mpla2 mpla2 mpla2 mpla2 mpla2 ENDMDL MISH |
| Sponsored Links | ||
|
|
|
#2
|
|||
|
|||
|
Try this: Code:
awk '/ENDMDL/{i++}{print > "file.pdb."i}' file |
|
#3
|
|||
|
|||
|
Cool...
|
|
#4
|
|||
|
|||
|
Hi Franklin52,
This works really well and its pretty quick. Mish |
|
#5
|
|||
|
|||
|
you can use below to set 'ENADMDL' as the line seperator instead of use the default '\n' Code:
$/="ENDMDL"; |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Split File Based on Line Number Pattern | shankster | Shell Programming and Scripting | 11 | 10-01-2008 09:49 AM |
| how to change a particular value in a file based on a pattern | orbeyen | UNIX for Dummies Questions & Answers | 9 | 08-20-2008 03:09 AM |
| Split a file based on pattern in awk, grep, sed or perl | kumarn | Shell Programming and Scripting | 5 | 06-20-2008 10:51 AM |
| Split a file with no pattern -- Split, Csplit, Awk | madhunk | UNIX for Dummies Questions & Answers | 10 | 12-17-2007 11:57 AM |
| awk script to split a file based on the condition | superprogrammer | Shell Programming and Scripting | 12 | 06-14-2005 03:59 AM |