熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Oracle >> 正文

如何用腳本實現分割文件

2022-06-13   來源: Oracle 

  #!/bin/bash
  if [ $# ne ]; then
   echo Usage: split file size(in bytes)
   exit
  fi
  file=$
  size=$
  if [ ! f $file ]; then
   echo $file doesnt exist
   exit
  fi
  #TODO: test if $size is a valid integer
  filesize=`/bin/ls l $file | awk {print $}`
  echo filesize: $filesize
  let pieces=$filesize/$size
  let remain=$filesize$pieces*$size
  if [ $remain gt ]; then
   let pieces=$pieces+
  fi
  echo pieces: $pieces
  i=
  while [ $i lt $pieces ];
  do
   echo split: $file$i:
   dd if=$file of=$file$i bs=$size count= skip=$i
   let i=$i+
  done
  echo #!/bin/bash > merge
  echo i= >> merge
  echo while [ $i lt $pieces ]; >> merge
  echo do >> merge
  echo echo merge: $file$i >> merge
  echo if [ ! f $file$i ]; then >> merge
  echo echo merge: $file$i missed >> merge
  echo rm f $rged >> merge
  echo exit >> merge
  echo fi >> merge
  echo dd if=$file$i of=$rged bs=$size count= seek=$i >> merge
  echo let i=$i+ >> merge
  echo done >> merge
  chmod u+x merge
From:http://tw.wingwit.com/Article/program/Oracle/201311/17694.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.