Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I haven't tried it yet, but I was thinking, concatenate would almost work,
cat File1 File2
Prints the combination to standard output, but what I need it to do is print it to File2, which is a devastating error. I guess it writes the first file to ouput and clears everything that was there, and then if the second file is also the output, it reads what was written to output, and just adds it, effectively duplicating.
I could write it to a new file, but then i have to copy files after anyways, no gain.
#WARNING: This is untested code.
for FILE in file1 file2 file3
dd if=$FILE of=tempfile bs=1 count=100
cat insertfile >> tempfile
dd if=$FILE of=tempfile2 bs=1 skip=100
cat tempfile2 >> tempfile
mv $FILE $FILE.bak
mv tempfile $FILE
rm -f tempfile2
I'm sure there is a utility just for this sort of thing but right off the top of my head I come up with this kludge.
You take the first 100 bytes of $FILE and put in tempfile. Then add insertfile. Then add the rest of $FILE. Rename everything and get rid of the mess you made. To insert somewhere else in the file just change count and skip.