Solved

tarring into multiple files

Posted on 1998-12-24
3
241 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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…

765 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