The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need help in splitting the file Vaddadi Shell Programming and Scripting 3 05-23-2008 10:44 AM
how to selectively mount FS? wrapster Shell Programming and Scripting 0 04-28-2008 10:44 AM
shell script to selectively tar directory based on date fara_aris Shell Programming and Scripting 2 03-16-2008 07:35 PM
file splitting UBD Shell Programming and Scripting 7 01-17-2008 03:24 PM
[Splitting file] Extracting group of segments from one file to others ozgurgul Shell Programming and Scripting 1 09-14-2006 01:17 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-10-2007
fusi0n fusi0n is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 2
Selectively splitting a file with C-shell?

I have a rather long csh script that works, but it's terribly ungraceful and takes a while from various loops. I only know enough code to get myself into trouble, so I'm looking for some guidance.

I have a large file that is separated at intervals by the same line, like this:

@<TRIPOS>molecule
name_000
blah
yadda
stuff
@<TRIPOS>molecule
name_001
blah2
yadda2
stuff2
@<TRIPOS>molecule
name_002
blah3
...

and so on for up to name_200, where blah/yadda/stuff are strings with numbers, letters, and white spaces.

I need to split this file into individual files, named name_000.mol2, name_001.mol2, name_002.mol2 etc, each of which contain:

@<TRIPOS>molecule
name_000 (or name_whatever)
blah
yadda
stuff

Currently I grep -n 'TRIPOS>molecule' the big file into another file, then use the line numbers to cycle through and pull out lines x through y, naming each file based on what's in line x+1 (name_000), with .mol2 on the end. This takes an incredibly long time, and is rather clunky. I don't know if it's the file cycling or all the variables I pass back and forth that eats up the time, but if anyone knows of an easier way to split the big file up, I would greatly appreciative!

I can't come up with a good way to do this in awk - the line numbers between each TRIPOS>molecule are variable, and my awk-fu is rather weak. I also need to keep this in CSH or I'll have to convert a ton of other code.

Any ideas?

Thanks!
  #2 (permalink)  
Old 12-11-2007
drl's Avatar
drl drl is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2007
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 717
Hi.

Does your system have commands csplit or split (with -p pattern)? ... cheers, drl
  #3 (permalink)  
Old 12-11-2007
fusi0n fusi0n is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 2
It does! I've never seen that before - I'll have to investigate.

Thanks!
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:29 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0