Jump to content
MSFN is made available via donations, subscriptions and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. ×

bash dd command question


Recommended Posts

Hi,

I have a number of splitted rar files, eg.:

file.part01.rar

file.part02.rar

.

.

.

file.partxx.rar

I need to add one 0 or NULL character at the end of every file.

I used the next command:

for i in "file*"; do sed -i '$s/$/0/' $i; done

but it's slow for large files (it read all content of files).

I tried to add the character NULL on those files with dd, but it works for one file/command line and I can't find a way to use wildcard with dd:

dd if=/dev/zero bs=1 count=1 >> 'file.part01.rar'

dd command works instantly even for a file with 1 GB size.

I need a command or a bash script that will add NULL character at the end of every file using dd command which is faster than sed.

Thanks!

Link to comment
Share on other sites


I need a command or a bash script that will add NULL character at the end of every file using dd command which is faster than sed.

Thanks!

But on which OS? Some Linux?

And why necessarily using dd?

 

What you want, more loosely, is to make each file one byte longer than what it is (the added byte will be a 0x00) i.e. to extend it's size, which is normally done with the (not particularly intuitively named ;)) truncate command:

http://linux.die.net/man/1/truncate

 

truncate --size=+1 <filename>

or

truncate --s +1 <filename>

should do.

 

Should be faster than dd. :unsure:

 

 

jaclaz

Edited by jaclaz
Link to comment
Share on other sites

I use Ubuntu. But how to write the command to process all files with this base name: file.partxx.rar?

I tried this:

for i in "file*"; do truncate --s +1 "file*"; done

which generate a file called file* with 1 byte size.

With sed was easy, but it's slow.

 

I succeeded with this:

for i in file.part*.rar; do truncate -s +1 file.part*.rar; done

Actually, the above command adds 5 bytes to the eof.

I used a wrong wild card for this command.

 

Thanks!

Edited by radix
Link to comment
Share on other sites

Wouldn't that be something *like*:

for f in *.rar; do truncate --s +1 "$f"; done

 

It's queer that you had 5 bytes added though. :unsure:

 

With dd it should be:

for f in *.rar; do dd if=/dev/zero bs=1 count=1 >> "$f"; done

 

jaclaz

Edited by jaclaz
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...