home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / unix / question / 14944 < prev    next >
Encoding:
Text File  |  1992-12-23  |  2.1 KB  |  69 lines

  1. Newsgroups: comp.unix.questions
  2. Path: sparky!uunet!murphy!jpradley!jpr
  3. From: jpr@jpradley.jpr.com (Jean-Pierre Radley)
  4. Subject: Re: How to chop up an archive.tar.Z file like in the X distributions?
  5. Date: Thu, 24 Dec 1992 02:16:21 GMT
  6. Message-ID: <1992Dec24.021621.8958@jpradley.jpr.com>
  7. References: <1992Dec15.142232.1@cc.utah.edu> <1992Dec19.053319.12598@jpradley.jpr.com>
  8. Organization: Unix in NYC
  9. Lines: 58
  10.  
  11. In article <1992Dec19.053319.12598@jpradley.jpr.com> jpr@jpradley.jpr.com (Jean-Pierre Radley) writes:
  12. >In article <1992Dec15.142232.1@cc.utah.edu> eyring@cc.utah.edu writes:
  13. >>
  14. >>Could someone tell me what unix utility was used to chop up 
  15. >>the big archive.tar.Z files into the smaller but all the same
  16. >>size files?
  17. >
  18. >When I'm faced with this task, I run "chunk":
  19. >
  20. >: chunk - breakup a file into SIZE chunks called PREFIX01, PREFIX02, ...
  21. ># @(#) JPRadley 10 Jan 91
  22. >[ ! -r "$1" ] && echo "Usage: $0 file [prefix [size]]" && exit
  23. >IN=$1 
  24. >PREFIX=${2:-chunk}
  25. >SIZE=${3:-100000}
  26. >N=0
  27. >while :
  28. >do
  29. >    T=`expr $N + 1`
  30. >    [ $T -le 9 ] && T=0$T
  31. >    dd count=1 bs=$SIZE if=$IN skip=$N of=$PREFIX$T
  32. >    [ ! -s $PREFIX$T ] && rm $PREFIX$T && break
  33. >    N=`expr $N + 1`
  34. >done
  35. >l $PREFIX* $IN
  36.  
  37.  
  38. That was last week. Now I'd use "mkparts":
  39.  
  40.  
  41. :
  42. # @(#) mkparts - chop a file into ~SIZE parts called PREFIX01, PREFIX02, ...
  43. # Each part, save the last, will be one byte larger than the one before it,
  44. # so that "by their size shall you know them".
  45. # @(#) JPRadley & RCStockler 22 Dec 92 - v1.0
  46. # N.B.: If your 'dd' doesn't understand 'iseek', use 'skip' instead.
  47.  
  48. [ ! -r "$1" ] && echo "Usage: $0 file [prefix [size]]" && exit
  49.  
  50. trap 'rm -f $TFILE.* ; trap 0 ; exit' 0 1 2 3 15
  51. IF=$1 PREFIX=${2:-part} SIZE=${3:-100000} PART=0 TFILE=/usr/tmp/mkp$$
  52. rm -f $PREFIX*
  53.  
  54. while [ -s $IF ]
  55. do
  56.   eval `awk '
  57.         END { printf( "SIZE=%d OLD=%02d PART=%02d", ++SIZE, PART, ++PART )
  58.         }' SIZE=$SIZE PART=$PART /dev/null`
  59.   dd count=1 bs=$SIZE if=$IF of=$PREFIX$PART 2>/dev/null
  60.   dd iseek=1 bs=$SIZE if=$IF of=$TFILE.$PART 2>/dev/null
  61.   IF=$TFILE.$PART
  62.   rm -f $TFILE.$OLD
  63. done
  64.  
  65. l $PREFIX* $1
  66.  
  67. -- 
  68. Jean-Pierre Radley   Unix in NYC   jpr@jpr.com   jpradley!jpr   CIS: 72160.1341
  69.