?
Solved

tarring into multiple files

Posted on 1998-12-24
3
Medium Priority
?
257 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 

Accepted Solution

by:
tangyw earned 200 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses
Course of the Month9 days, 13 hours left to enroll

762 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