LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-05-2009, 06:14 AM   #1
hifun
LQ Newbie
 
Registered: Dec 2008
Distribution: Fedora 8
Posts: 28

Rep: Reputation: 15
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?
 
Old 04-05-2009, 06:32 AM   #2
JulianTosh
Member
 
Registered: Sep 2007
Location: Las Vegas, NV
Distribution: Fedora / CentOS
Posts: 674
Blog Entries: 3

Rep: Reputation: 90
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.
 
Old 04-05-2009, 11:04 AM   #3
hifun
LQ Newbie
 
Registered: Dec 2008
Distribution: Fedora 8
Posts: 28

Original Poster
Rep: Reputation: 15
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.
 
Old 04-05-2009, 04:35 PM   #4
JulianTosh
Member
 
Registered: Sep 2007
Location: Las Vegas, NV
Distribution: Fedora / CentOS
Posts: 674
Blog Entries: 3

Rep: Reputation: 90
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
wget - how to download more than one file at once instead of file after file? De-M-oN Linux - Server 15 09-24-2010 05:35 PM
Display by File Name, File Size, and File Owner using ls akeenabawa Linux - Newbie 9 08-15-2008 02:21 PM
How can read from file.txt C++ where can save this file(file.txt) to start reading sam_22 Programming 1 01-11-2007 05:11 PM
gave wrong syntax for tar as tar -cvzf file file.tgz how to recover the file gautham Linux - General 4 04-13-2005 03:15 AM
How to play a media file/ video file/mp3 file recorded in harddisk/cd-rom arindam Linux - Newbie 2 09-05-2003 10:31 AM


All times are GMT -5. The time now is 10:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration