Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account



Photo

bash dd command question

- - - - -

  • Please log in to reply
2 replies to this topic

#1
radix

radix

    Friend of MSFN

  • Member
  • PipPipPipPipPip
  • 754 posts
  • Joined 08-February 07
  • OS:Windows 8 x64
  • Country: Country Flag

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!




How to remove advertisement from MSFN

#2
jaclaz

jaclaz

    The Finder

  • Developer
  • 15,621 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag

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, Today, 12:15 PM.


#3
radix

radix

    Friend of MSFN

  • Member
  • PipPipPipPipPip
  • 754 posts
  • Joined 08-February 07
  • OS:Windows 8 x64
  • Country: Country Flag

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, Today, 04:00 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users