LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to divide file by half in Linux? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-divide-file-by-half-in-linux-374283/)

mac1234mac 10-18-2005 10:39 AM

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?.

anomie 10-18-2005 10:41 AM

See the
Code:

man split
pages.

ilikejam 10-18-2005 10:47 AM

Also,
Code:

man cat
to put the bits back together again.

Dave

mac1234mac 10-18-2005 10:47 AM

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.)

halo14 10-18-2005 11:16 AM

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...

mac1234mac 10-18-2005 11:24 AM

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.

Matir 10-18-2005 12:26 PM

As an FYI, you can do a pseudo-cat under windows:
Code:

copy /b file1+file2 file3

halo14 10-18-2005 01:39 PM

wow... if that works that's cool, Matir... I shall try it.

I was also unaware that WinRAR can do that...

heema 10-19-2005 05:44 AM

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


blindcoder 10-19-2005 08:40 AM

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

Greetings,
Benjamin

heema 10-19-2005 10:52 AM

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

blindcoder 10-19-2005 03:16 PM

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 :)


All times are GMT -5. The time now is 04:34 PM.