radix Posted June 29, 2015 Share Posted June 29, 2015 Hi,I have a number of splitted rar files, eg.:file.part01.rarfile.part02.rar...file.partxx.rarI 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; donebut 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 More sharing options...
jaclaz Posted June 29, 2015 Share Posted June 29, 2015 (edited) 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>ortruncate --s +1 <filename>should do. Should be faster than dd. jaclaz Edited June 29, 2015 by jaclaz Link to comment Share on other sites More sharing options...
radix Posted June 29, 2015 Author Share Posted June 29, 2015 (edited) 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*"; donewhich 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; doneActually, the above command adds 5 bytes to the eof.I used a wrong wild card for this command. Thanks! Edited June 29, 2015 by radix Link to comment Share on other sites More sharing options...
jaclaz Posted June 30, 2015 Share Posted June 30, 2015 (edited) 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. With dd it should be:for f in *.rar; do dd if=/dev/zero bs=1 count=1 >> "$f"; done jaclaz Edited June 30, 2015 by jaclaz Link to comment Share on other sites More sharing options...
radix Posted June 30, 2015 Author Share Posted June 30, 2015 Thanks for polishing the command! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now