LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 04-30-2023, 07:03 AM   #1
ramonun
LQ Newbie
 
Registered: Apr 2023
Posts: 4

Rep: Reputation: 0
How can I split a set of bytes into separate parts


Code:
$ du -b 1GB.bin
1048576000      1GB.bin

$ split --verbose -b 120M 1GB.bin && du -b *xa*
125829120       xaa
125829120       xab
125829120       xac
125829120       xad
125829120       xae
125829120       xaf
125829120       xag
125829120       xah
41943040        xai
How can I split or divide the 1048576000 bytes above, or even bigger: 2GiB = 2147483648 bytes or 3GiB = 3221225472 bytes and so on, but without having to use the split utility, so that the result is exactly as above (per part is 120 MiB = 125829120 bytes, except for the last part, 40 MiB = 41943040 bytes) ?.

Last edited by ramonun; 04-30-2023 at 07:26 AM.
 
Old 04-30-2023, 08:09 AM   #2
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,781

Rep: Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198
split without split?
You can use dd and a lot of shell code, but why?
 
Old 04-30-2023, 08:15 AM   #3
ramonun
LQ Newbie
 
Registered: Apr 2023
Posts: 4

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by MadeInGermany View Post
split without split?. You can use dd and a lot of shell code, but why?
The file hosting where I put the files allows for multipart uploads without having to split files. And would you like to give me an example of using dd based on my post above? Thank You.
 
Old 04-30-2023, 09:34 AM   #4
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Quote:
Originally Posted by ramonun View Post
The file hosting where I put the files allows for multipart uploads without having to split files. And would you like to give me an example of using dd based on my post above? Thank You.
It's all in the dd manual page.
count, skip, and bs arguments.
 
Old 04-30-2023, 10:34 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,804

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
you can use a lot of tools like perl, python, dd, whatever, to count/copy XX bytes. But why do you want to reinvent split?
 
Old 04-30-2023, 10:53 AM   #6
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,136
Blog Entries: 6

Rep: Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826
Simple Example:
Code:
touch myfile

for i in {1..100000}; do
    echo "$i" >> myfile
done

ls -l myfile
-rw-r--r-- 1 me me 588895 Apr 30 10:41 myfile

dd if=myfile of=myfile2 bs=10k count=1
dd if=myfile of=myfile3 bs=10k skip=1 count=1
dd if=myfile of=myfile4 bs=10k skip=2 count=1
Look at myfile2 3 and 4
 
1 members found this post helpful.
Old 04-30-2023, 10:54 AM   #7
ramonun
LQ Newbie
 
Registered: Apr 2023
Posts: 4

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by pan64 View Post
you can use a lot of tools like perl, python, dd, whatever, to count/copy XX bytes. But why do you want to reinvent split?
Read my reply here please.
 
Old 04-30-2023, 11:39 AM   #8
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,804

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
Quote:
Originally Posted by ramonun View Post
Read my reply here please.
that is not an answer. At least I don't understand. However, you can still use a lot of different tools instead of split.
https://stackoverflow.com/questions/...file-in-python
 
Old 04-30-2023, 01:40 PM   #9
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Quote:
Originally Posted by ramonun View Post
Read my reply here please.
Read my reply here please.

You asked about dd, I've cited the argument options you can use.

Given the demonstrable, and good split command you've shown, this should not be too difficult.

Further, one can use a very small, text file and experiment to ensure they know how to use the command arguments to attain their desired result.

Edit: also look at what user teckk posted, a dd example

Last edited by rtmistler; 05-01-2023 at 10:07 AM.
 
  


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
[SOLVED] [Kali Linux] How do i split a 15.7GB text file into 3 parts also... ArtiSeven Linux - Newbie 18 04-11-2015 03:51 PM
[SOLVED] split huge file into small parts and compress them. xeon123 Linux - General 5 06-02-2011 04:17 AM
Can tar split archives into parts? Rotwang Linux - General 1 12-21-2007 03:14 PM

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

All times are GMT -5. The time now is 12:42 PM.

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