Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Split a file into fixed-size pieces

Status
Not open for further replies.

hisham

IS-IT--Management
Nov 6, 2000
194
I have a text file "myfile.txt" size 15MB. i want to Split this file into fixed-size 5 pieces using split command.
any help?
Thanx in advance.
 
use [tt]dd[/tt].

dd if=file.txt of=output1.txt count=300 bs=1024

or somthing like that.

Cheers.
 
Here is a quick and dirty script I came up with to split an input file into mutiple 500k chunks. Just pass a filename as a parameter. You can put the chunks back by using: cat chunk-1 chunk-2 chunk-n > singlefile

#!/bin/bash
filesize=`stat -c %s $1`
processed=0
partcount=1

while (( $processed <= $filesize ))
do
dd if=$1 of=$1.part$partcount bs=1 skip=$processed count=500000
processed=`expr $processed + 500000`
partcount=`expr $partcount + 1`
done


--== Anything can go wrong. It's just a matter of how far wrong it will go till people think its right. ==--
 
split -b or split -l, depending on whether you want to split it by lines or bytes. See "man split"



Tony Lawrence
Linux/Unix/Mac OS X Resources
 
thank you all.
i found that :
split -b3M myfile.txt myfile.txt
work too.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top