Selectively splitting a file with C-shell?

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Selectively splitting a file with C-shell?
# 1  
Old 12-10-2007
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:


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:

name_000 (or name_whatever)

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?

# 2  
Old 12-11-2007

Does your system have commands csplit or split (with -p pattern)? ... cheers, drl
# 3  
Old 12-11-2007
It does! I've never seen that before - I'll have to investigate.

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Selectively extracting entries from FASTA file

I would like to extract all entries containing the following patterns: ccccta & ccccccccc from the following infile: >P39PT-1224_Freq_900 cccctacgacggcattggtaatggctcccgcaagccatctctcttcagccaagg >P39PT-784_Freq_2 cccctacgacggcattggtaatggcacccgcaagccatctctcttccccccccc >P39PT-678_Freq_5... (4 Replies)
Discussion started by: Xterra
4 Replies

2. Shell Programming and Scripting

How to remove spaces from a file selectively?

Hi i have a file in which i am doing some processing. The code is as follows: #!/bin/ksh grep DATA File1.txt >> File2.txt sed 's/DATA//' File2.txt | tr -d >> File4.xls As you can see my output is going in a xl file.The output consist of four columns/feilds out of which the first... (20 Replies)
Discussion started by: Sharma331
20 Replies

3. Shell Programming and Scripting

echo ls to a file and then read file and selectively delete

I'm trying to write a script that will do an ls of a location, echo it into a file, and then read that file and selectively delete files/folders, so it would go something like this: cd $CLEAN_LOCN ls >>$TMP_FILE while read LINE do if LINE = $DONTDELETE skip elseif LINE =... (2 Replies)
Discussion started by: MaureenT
2 Replies

4. Shell Programming and Scripting

Selectively Find/Replace in a file?

I have a file that is HTML encoded. Each line has something like this on each line.. <href=>username </a> more info.. <a href=>info1</a> more code... <a href=>info2</a> I have one goal really.. to clean up the... (2 Replies)
Discussion started by: dragin33
2 Replies

5. Shell Programming and Scripting

Help with shell script - splitting

Hi, I need to split the file lines in below format as. Input file : Sample.txt <Rule expression="DeliverToCompID IS NULL" invert="true"> <Rule field="PossDupFlag" value="Y" > <Rule expression="OrdStatus = '2' AND OrigClOrdID IS NULL"> Output... (5 Replies)
Discussion started by: manosubsulo
5 Replies

6. UNIX for Dummies Questions & Answers

Removing selectively the last character from a file

Dear Members, Problem is suppose i have 50 lines in a file, 40 lines last character is "\" and the remaining 10 lines are good(i mean these 10 lines do not have "\" character) How can i remove this character from the file. Thanks (1 Reply)
Discussion started by: sandeep_1105
1 Replies

7. Shell Programming and Scripting

shell - word splitting - using eval

In POSIX shell, we don't have arrays, but we can iterate over a list like this: #!/bin/sh list="Fred Barney Wilma Betty" for i in $list; do echo $i; done Fred Barney Wilma Betty But let's say we want "Mr. Slate" in the list. We know we can't just stick him in there like this:... (5 Replies)
Discussion started by: mjd_tech
5 Replies

8. UNIX for Advanced & Expert Users

Selectively Reformating a file using AWK

Dear users, I am new to AWK and have been battling with this one for close to a week now. Some of you did offer some help last week but I think I may not have explained myself very well. So I am trying again. I have a dataset that has the following format where the datasets repeat every... (5 Replies)
Discussion started by: sda_rr
5 Replies

9. UNIX for Dummies Questions & Answers

splitting shell window

hi is it possible to split the shell window in two or more parts like split command vi? i am using putty as telnet client. (2 Replies)
Discussion started by: ilayans
2 Replies

10. Shell Programming and Scripting

shell script to selectively tar directory based on date

hye everybody :) , i'm new to the scripting world.. hope you guys can help me out with this one.. i'm trying to identify any directory under /tmp/saya that is created more than one day from the current date.. e.g, today is March 14, so any directory that has time stamp March 13 backwards, i... (2 Replies)
Discussion started by: fara_aris
2 Replies
Login or Register to Ask a Question