Solved

tarring into multiple files

Posted on 1998-12-24
3
229 Views
Last Modified: 2010-04-21
Hi...

Suppose that I have a file of size 20MB...

Is there a way that I can split it into 4 5MB files on a unix machine, and then transfer them onto a windows machine and rejoin the 4 files into 1 file?

Thanks
0
Comment
Question by:applecrusher
3 Comments
 

Accepted Solution

by:
tangyw earned 100 total points
ID: 2008501
Hi

Assume that
1. There is no LAN between your machines.
2. The file already be compressed. ( Now is binary file ).

So you can do it as follows:
1. Make a program to split your file into smaller size which you wanted.
2. Copy these splited files onto your windows machine.
3. Use DOS command to rejoin them.
   c:copy /b file01+file02+file03+file04 yourfile

Sample program:
#include      <stdio.h>

#define            BUFSIZE            1024
main( argc, argv )
int            argc;
char      **argv;
{
      FILE      *ifp, *ofp;
      char      buffer[BUFSIZE];
      char      FileName[128];
      int            i, FileNum, FileSize, EndFlag;
      long      readn;

      if ( argc < 3 ) {
            printf("Usage: %s filename size(Kbyte)\n", argv[0]);
            exit( 1 );
      }
      if ((ifp=fopen(argv[1],"rb")) == NULL ) {
            printf("File %s open error!\n", argv[1]);
            exit( 2 );
      }
      sscanf( argv[2], " %d", &FileSize );
      FileNum = 1;
      EndFlag = 0;
      while ( !EndFlag ) {
            sprintf(FileName, "%s%02d", argv[1], FileNum );
            if ( (ofp=fopen(FileName, "wb")) == NULL ) {
                  printf("File %s create error!\n", FileName);
                  exit( 3 );
            }
            for ( i=0; i<FileSize; i++ ) {
                  if ((readn=fread(buffer, sizeof(char),BUFSIZE, ifp )) == 0 ) {
                        EndFlag = 1;
                        break;
                  }
                  fwrite(buffer, sizeof(char), readn, ofp );
            }
            fclose( ofp );
            FileNum++;
      }
      fclose( ifp );
}

Have a good holiday!
-Tang
0
 
LVL 1

Expert Comment

by:toTo
ID: 2008502
there is a command named split that already does the job
you can  Split a File Into Multiple Files Containing
a Specified Number of Lines or of Bytes

0
 

Author Comment

by:applecrusher
ID: 2008503
someone gave me a much easier way........

in unix:
split -b5m file files

in dos:
copy /b files* file


much easier don't u think!!!!!!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now