LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-18-2005, 10:39 AM   #1
mac1234mac
Member
 
Registered: Sep 2005
Posts: 183

Rep: Reputation: 30
How to divide file by half in Linux?


I want to move 650Meg file from computer to computer via MP3 Player (512Meg drive) and
I need to divide the file under linux. How to do it?.
 
Old 10-18-2005, 10:41 AM   #2
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
See the
Code:
man split
pages.
 
Old 10-18-2005, 10:47 AM   #3
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 97
Also,
Code:
man cat
to put the bits back together again.

Dave
 
Old 10-18-2005, 10:47 AM   #4
mac1234mac
Member
 
Registered: Sep 2005
Posts: 183

Original Poster
Rep: Reputation: 30
I forgot to add that I have to merge this file in Windows so it would have to be some
packer that works with windows(rar, arj, zip etc.)
 
Old 10-18-2005, 11:16 AM   #5
halo14
Senior Member
 
Registered: Apr 2004
Location: Surprise, AZ
Distribution: Debian | CentOS | Arch
Posts: 1,103

Rep: Reputation: 45
that's not gonna happen.. you need to use a network of some kind..null modem, crossover cable, hub/switch, whatever.. something... split and cat are excellent tools... i often use it for emailing large file via gmail... just send them in several small pieces.. the only other way i see to do it is if there is a FAT partition on the windows machine, you could use a livecd (knoppix, dsl, etc) to boot.. copy the files over, cat them back together, then boot windows and have the full file...

even if you temporarily added a second hard drive the other machine for this purpose, it would be easy.

I don't know of any apps for Windows than will pice together sections of a file though...
 
Old 10-18-2005, 11:24 AM   #6
mac1234mac
Member
 
Registered: Sep 2005
Posts: 183

Original Poster
Rep: Reputation: 30
Thanks that's some thought... But I discovered RAR in linux. One can divide files
with it as well, but your way is good as well.
 
Old 10-18-2005, 12:26 PM   #7
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
As an FYI, you can do a pseudo-cat under windows:
Code:
copy /b file1+file2 file3
 
Old 10-18-2005, 01:39 PM   #8
halo14
Senior Member
 
Registered: Apr 2004
Location: Surprise, AZ
Distribution: Debian | CentOS | Arch
Posts: 1,103

Rep: Reputation: 45
wow... if that works that's cool, Matir... I shall try it.

I was also unaware that WinRAR can do that...
 
Old 10-19-2005, 05:44 AM   #9
heema
Senior Member
 
Registered: Sep 2003
Location: Egypt
Distribution: Arch
Posts: 1,528

Rep: Reputation: 47
i made a script before that will split a file to specified size, split a file to specified number of parts, combine the files, make windows batch file to combine the files in windows

Code:
#!/bin/bash

###########################################################
#
# isplit	splits and combine files
# 
# Made By : ibrahim riad  (Heema)
#
###########################################################


###########################################################
# Main
###########################################################

if [ $# -eq 0 ];then
	echo ""
	echo "Usage : isplit [option] filename"
	echo "option : -s	split file to specified size"
	echo "         -p	split file to specified parts"
	echo "         -c	combine the files"
	echo "         -w	make windows batch file to combine the files in windows
"


	echo ""
	exit
fi

if [ $# -eq 2 ];then
	filepath=$2
	
fi

#echo "Filepath : $filepath"
#echo "num : $#"

###########################################################

case "$1" in

###########################################################
# Split file
###########################################################

-s)
	echo -n "Enter desired size (MB) : "
	read size
	
	split -b "$size"m "$filepath" "$filepath".

	echo "$filepath" > $HOME/.ksplittemp
;;

###########################################################
# Split file to specified parts
###########################################################

-p)
		
	echo -n "Enter desired parts : "
	read parts
	
	info=$(ls -l $filepath | awk '{print $5}')
	
	partsize=$((($info/$parts)+1))

	split -b "$partsize" "$filepath" "$filepath".

	echo "$filepath" > $HOME/.ksplittemp

;;

###########################################################
# Combine the files
###########################################################

-c)
		
	BASE=$(basename "$filepath" | cut -d . -f1)
	
	guess=$(cat $HOME/.ksplittemp)

	guessname=$(basename "$guess")
	
	
	echo -n "Do you want the name of the output to be $guessname  (y/n) : "
	read answer
	
	if [ "$answer" == "y" ];then
		echo ""
	else
		echo -n "Enter output name : "
		read outputname
		cat "$BASE".* > "$outputname"
	fi


	cat "$BASE".* > "$guessname"
	
;;

###########################################################
# Make windows batch file to combine the files in win$
###########################################################

-w)
	
	basefile=$(basename "$filepath" | cut -d . -f1)
	
	guessing=$(cat $HOME/.ksplittemp)

	guessingname=$(basename $guessing)

	
	echo -e "@ echo off\n" > winbatch.bat
	echo -e "clr\n" >> winbatch.bat
	echo -e "\n" >> winbatch.bat
	echo -e "copy /B $basefile.a* $guessingname \n" >> winbatch.bat
	echo -e "\n" >> winbatch.bat
	echo -e "echo on\n" >> winbatch.bat 

;;
	
*)
	echo -e "\033[0;31mThis format is not supported\033[0m"
;;

esac

Last edited by heema; 10-19-2005 at 10:53 AM.
 
Old 10-19-2005, 08:40 AM   #10
blindcoder
ROCK Linux
 
Registered: Dec 2003
Location: Berlin, Germany
Distribution: Crystal ROCK
Posts: 108

Rep: Reputation: 15
Looks like a nice and useful script. Mind me (or yourself) adding it to http://shellscripts.org?

Greetings,
Benjamin
 
Old 10-19-2005, 10:52 AM   #11
heema
Senior Member
 
Registered: Sep 2003
Location: Egypt
Distribution: Arch
Posts: 1,528

Rep: Reputation: 47
Quote:
Originally posted by blindcoder
Looks like a nice and useful script. Mind me (or yourself) adding it to http://shellscripts.org?

Greetings,
Benjamin
I added it

and nice site by the way
 
Old 10-19-2005, 03:16 PM   #12
blindcoder
ROCK Linux
 
Registered: Dec 2003
Location: Berlin, Germany
Distribution: Crystal ROCK
Posts: 108

Rep: Reputation: 15
Quote:
Originally posted by heema
I added it
and nice site by the way
Thanks. I really only created it to have a "dump" for all the little shellscripts
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how do I install half windows98 half linux? xandar Linux - General 3 09-07-2005 03:23 AM
cant divide with C skoot Programming 23 08-26-2005 06:50 PM
Partimage & Divide by Zero KimVette Linux - Hardware 3 06-01-2005 10:18 AM
Half of My .zip file got lost? Diademed Linux - Software 2 11-05-2004 03:27 AM
Divide a file into 2 parts bmbsa Linux - Newbie 3 08-13-2003 04:08 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration