LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   file compactation (https://www.linuxquestions.org/questions/linux-newbie-8/file-compactation-716962/)

hifun 04-05-2009 06:14 AM

file compactation
 
I need to remove user specified bytes ( could be in between) from file and then compact the file.All I got is brute-force method. Say user says to remove bytes 5-10 from file of size 100 bytes, then I'am shifting 90 bytes of data( bytes 11 to 100) back to 5 bytes.
Any other optimal approach or system call which could make this efficient?

JulianTosh 04-05-2009 06:32 AM

Code:

dd if=/tmp/test bs=1 skip=5 count=5
By calculating your skip and count based on the user input, you can string one or two 'dd's together to accomplish what you need.

hifun 04-05-2009 11:04 AM

Admiral Beotch,
I think you didnt get me. Say a file contain data as "Linuxquestions.org" total of 17 bytes, now if user want to remove bytes 6-14 then content of file should be "Linux.org".I am asking for efficient method to do this.And yes preferably through C program.

JulianTosh 04-05-2009 04:35 PM

I got what you meant. This is what I was talking about:

'skip.sh 5 14'
Code:

skipBegin=$1
skipEnd=$2

echo "Linuxquestions.org" > /tmp/file.dat
dd if=/tmp/file.dat bs=1 skip=0 count=$skipBegin of=/tmp/file1.dat
dd if=/tmp/file.dat bs=1 skip=$skipEnd of=/tmp/file2.dat
cat /tmp/file?.dat

This, of course, is a bash script and not C code, so I guess it's not what you're looking for.


All times are GMT -5. The time now is 04:02 PM.