LinuxQuestions.org
Register a domain and help support LQ
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 02-26-2013, 09:21 AM   #1
AdamD
LQ Newbie
 
Registered: Feb 2013
Location: oxon, uk
Distribution: RH5, UBUNTU
Posts: 7

Rep: Reputation: Disabled
Combine files with offset


Hi, my first post so hello everyone!

I'll get straight to the point - I have four files that I want to combine together but with an offset applied to each file. So fileA starts at 0x00, fileB starts at 0x9C4000, fileC starts at 0xCB2000 and fileD starts at 0xCC0000. What fills the gap between files is not important, what is important is the start byte location of each file. FileA is .SREC file, B is a .xmp file, C is .html file and D is .js file. The output file can output in the form of a text file.

I have tried "cat" but there doesn't seem to be an option to control how the files are concatinated.

Any help will be much appreciated

Regards
AdamD

Last edited by AdamD; 02-26-2013 at 09:44 AM.
 
Old 02-26-2013, 09:47 AM   #2
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Could you show us some sample with dummy entries? Many commands and combination of commands can do this, but without visualizing the requirement, it's not appropriate to suggest anything.
 
Old 02-26-2013, 11:00 AM   #3
AdamD
LQ Newbie
 
Registered: Feb 2013
Location: oxon, uk
Distribution: RH5, UBUNTU
Posts: 7

Original Poster
Rep: Reputation: Disabled
Hi Shivaa,

Many thanks for the reply.

The output file combining Files A,B,C,D should be in the form of the following. The gaps between each file start point can be filled with 0's. I hope this explains it a little better.

|0--------------------|10,240,000-----------|13,312,000-----------|13,369,344
[.....FILE A....]000..000[.....FILE B....]000..000[.....FILE C....]000..000[.....FILE D....]


FileA - start byte 0 - Filetype .SREC (this line not needed in output)
S02B0000533A2F50726F6A656374732F495349535F43686F70706572732F4D4B335F4D504455312F4649524DA7
S315000000009421FF609001002490410028BC61002CDF
S315000000107C0802A6900100107C0902A6900100143B
..."continues with many similar lines"
S315FFFFFFEC3C000000600020C47C0803A64E80002066
S309FFFFFFFC4BFFFFF0C4
S705FFFFFFFC01
000000000000000000000 - as many '0' required to fill file to 0x9c4000 or byte number 10,239,999

FileB start byte 10,240,00 - Filetype .xap (this is a bin file and hence characters do not display properly, this line not needed in output)
PK
p~Ať{ lv
..."continues with many similar lines unable to display in this box"
@
000000000000000000000 - as many '0' required to fill file to 0xCB2000 or byte number 13,311,999

FileC start byte 13,312,000 - Filetype .html (this line not needed in output)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >

<head>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
..."continues with many similar lines"
</a>
</object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>
</form>
</body>
</html>
000000000000000000000 - as many '0' required to fill file to 0xCC0000 or byte number 13,369,343

FileD start byte 13,369,344 - filetype .js (this line not needed in output)
//v2.0.30511.0
if(!window.Silverlight)window.Silverlight={};Silverlight._silverlightCount=0;Silverlight.__onSilverl ightInstalledCalled=false;Silverlight.fwlinkRoot="http
..."continues with many similar lines"
__installationEventFired){a();Silverlight.__installationEventFired=true}}catch(e){}return c}

Last edited by AdamD; 02-26-2013 at 11:03 AM.
 
Old 02-26-2013, 11:17 AM   #4
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,267

Rep: Reputation: 298Reputation: 298Reputation: 298
Hi

It could be done with cat and truncate, something like this:
Code:
COMBINEDFILE=/tmp/bigfile
cat fileA > $COMBINEDFILE
truncate -s $((0x9C4000)) $COMBINEDFILE
cat fileB >> $COMBINEDFILE
truncate -s $((0xCB2000)) $COMBINEDFILE
cat fileC >> $COMBINEDFILE
truncate -s $((0x9C4000)) $COMBINEDFILE
cat fileC >> $COMBINEDFILE
truncate -s $((0xCC0000)) $COMBINEDFILE
Using truncate has the benefit that the file will become "sparse", so it wont take much disk space.
 
Old 02-26-2013, 12:00 PM   #5
AdamD
LQ Newbie
 
Registered: Feb 2013
Location: oxon, uk
Distribution: RH5, UBUNTU
Posts: 7

Original Poster
Rep: Reputation: Disabled
Hi Guttorm,

Many thanks for the reply. I keep getting "truncate : command not found" when I run this. Has this function / prototype got to be included somehow? I am using RH5 if this helps.. If I "man truncate" it comes up with the doc for it but doesn't execute. I see it's in unistd.h and sys/types.h, any pointers???

Many thanks
AdamD
 
Old 02-26-2013, 12:04 PM   #6
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,267

Rep: Reputation: 298Reputation: 298Reputation: 298
Hi

Sorry don't know about RH5. On Debian the truncate command is in a package called coreutils. Maybe use your package manager to search for it?
 
Old 02-26-2013, 12:24 PM   #7
AdamD
LQ Newbie
 
Registered: Feb 2013
Location: oxon, uk
Distribution: RH5, UBUNTU
Posts: 7

Original Poster
Rep: Reputation: Disabled
Hi,

If I "whereis truncate" I get "truncate: /usr/share/man/man3p/truncate.3p.gz /usr/share/man/man2/truncate.2.gz"

So it seems I have the manual for it but it's a function that is not installed on our systems. Nothing I can do about that unfortunately but I'm sure it would have worked all the same. I'll have a chat with our IT guys and see if it can be installed. Also, it might be a permission thing..

Thanks for your reply though
Regards
AdamD
 
Old 02-26-2013, 01:00 PM   #8
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,267

Rep: Reputation: 298Reputation: 298Reputation: 298
You could also use dd for this.

Code:
COMBINEDFILE=/tmp/bigfile
dd conv=notrunc bs=1 if=fileA of=$COMBINEDFILE seek=0 
dd conv=notrunc bs=1 if=fileB of=$COMBINEDFILE seek=$((0x9C4000))
dd conv=notrunc bs=1 if=fileC of=$COMBINEDFILE seek=$((0xCB2000))
dd conv=notrunc bs=1 if=fileD of=$COMBINEDFILE seek=$((0xCC0000))
 
2 members found this post helpful.
Old 02-27-2013, 03:51 AM   #9
AdamD
LQ Newbie
 
Registered: Feb 2013
Location: oxon, uk
Distribution: RH5, UBUNTU
Posts: 7

Original Poster
Rep: Reputation: Disabled
Hi Guttorm,

I think you have cracked it!

I tried it last night and it seems to have worked. I will try to program the file into the flash memory today to see if it locates the files in the correct places and let you know how it goes.

Thank you (Tusen Takk)
 
Old 02-27-2013, 04:44 AM   #10
AdamD
LQ Newbie
 
Registered: Feb 2013
Location: oxon, uk
Distribution: RH5, UBUNTU
Posts: 7

Original Poster
Rep: Reputation: Disabled
Hi Guttorm,

Yes, just tried it and this works - Brilliant!!

Thanks again
AdamD
 
  


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
[SOLVED] awk question - read in txt files, offset data by given amount, output new txt files pomico Programming 19 09-17-2012 12:43 PM
[SOLVED] Combine 3 text files into 1 W_Bosman Linux - Newbie 7 09-01-2010 06:28 PM
combine two files Syed Tarique Moin Programming 16 07-05-2010 12:30 PM
Using GAWK to combine files paragkalra Programming 4 11-14-2009 08:43 AM
Best way to combine files? JockVSJock Programming 4 04-25-2004 08:38 PM


All times are GMT -5. The time now is 11:56 AM.

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