The split Command


The split Command

Now that you know how to find out how much data is in a file, and what that file is comprised of logically to build up its internal structure, we will look at how to take a large file and break it down. The split command will do just that. It will cut down a file into whatever length you specify. To use the split command you need only to know that a file is too large to work with or to send to someone. Once this is determined, you can execute the split command to break it down. To split the file, take the following steps:

1.

Choose your input file that you want to beak down. For example, I still have that boot log that is large, so I will break that down into manageable chunks.

2.

Determine the number of lines you want stored in each output file. Understanding how to determine how many lines there are is important. This will help you determine what the sizing will be for the split. Do this by using -l <number of lines> as an option to the sort command.

3.

Choose a base output filename for the results.

4.

Invoke split using the following syntax: split <segment options> <inputfile> <outputfile>.

An example of this functionality:

 >split -l 3 boot.msg splitfile 

The boot.msg file from the previous example has been run through split and has been divided into two files of three lines each. The l option specified the 3 lines each. It's important to know this command if you want to break data down into manageable chunks so that you can either work with them or send them to others.

You may be wondering how you reassemble a file after you break and split it up. You can do this with a previously learned command, the cat command.

You need to reassemble your files that you just split. To do this, you need to use the cat command. When you have a series of files named with something such as <name> (<name>aa, <basename>ab, <basename>ac<basename>zz), you can reassemble them by issuing the cat command as follows: cat <basename>* > combine_complete.file. This will reassemble your files so that you can work with them.

Another handy set of utilities you will come to love is the patch and diff commands. These utilities will also help you with your Unix file management.



    SAMS Teach Yourself Unix in 10 Minutes
    Sams Teach Yourself Unix in 10 Minutes (2nd Edition)
    ISBN: 0672327643
    EAN: 2147483647
    Year: 2005
    Pages: 170

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net