Smart File Splitters: split, csplit, fsplit



next up previous contents index
Next: Sort Up: Unix Toolkit Previous: Translate Characters: tr

Smart File Splitters: split, csplit, fsplit

When transferring, moving, or searching through a large number of Fortran or C subroutines, it is often easier to copy all the subroutines into one file and then work with just the one large file rather than many small ones. For example, to copy all files with .f or .c suffixes into the one file all, first create all (perhaps with cat) and then concatenate all subroutines into all:
       

% cat *.f  >> all   	Add all .f files to end of all.   
%    	Unix returns prompt when done.   

If you want to compile all, which for Fortran requires a file ending with .f and for the C language requires a file ending with .c, you now move all to all.f or all.c:

% mv  all  all.f   	Renames all to all.f for compiler.   
% mv  all  all.c   	Renames all to all.c for compiler.   

Note, if you had first created all.f and then tried

% cat  *.f  >>  all.f   	Copy all .f  files to end of all.f ,   

Unix would say you were naughty by trying to copy a file onto itself.
When you are done working with all.f or all.c, it is split back into individual subprograms with the split commands:

% fsplit  all.f   	Break all.f into individual subs.    
% csplit  all.c   	Break all.c into individual subs.   

After splitting (but before you and the computer split) it's a good idea to remove the big file:

% rm all.f (all.c)   	Conserve disk space.   

By having some @PROCESS or similar compiler directive statements preceding your subroutine declarations may keep fsplit or csplit from knowing where that subroutine begins. The spilt command is a general utility that will break up any text file into small parts. It is useful for splitting files into small pieces for mailing.



next up previous contents index
Next: Sort Up: Unix Toolkit Previous: Translate Characters: tr