Sponsored Content
Top Forums Shell Programming and Scripting Remove first N bytes and last N bytes from a binary file on AIX. Post 302198845 by robotronic on Saturday 24th of May 2008 11:06:48 AM
Old 05-24-2008
If you are manipulating binary files, you cannot use awk or sed. Give a look at "dd" man page and try something like this:

Code:
dd if=input.bin of=output.bin bs=1 skip=X count=Y

Where X is the number of bytes you want to remove from the beginning, and Y is the number of bytes you want to process before the end of file.

Suppose you have a binary files which is 100 bytes in size and you want to remove the first 10 bytes and the last 5 bytes, obtaining an 85 bytes output.
The value of X will be 10, while the value of Y will be 85 (=100-10-5). You can find file size with a simple "ls" or "wc -c" command.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

delete bytes from file

I'm doing a bit of hex editing with dd and I can replace values fairly simply. However, I've run across a situation where I need to delete bytes in the file and I'm not sure how to do that. For example: Input file has: 1234567890 Output needs to be: 123abc90 I tried this: printf... (6 Replies)
Discussion started by: Loriel
6 Replies

2. Shell Programming and Scripting

AIX/HPUX - Need to get the last few bytes of a text

Hi guys, I am in need of a simple, (typically one-liner) script to get the last 17 bytes of a line. Eg. echo "abcdefghijklmnopqrstuv" here i would need the last 17 bytes of the text ie. fghijklmnopqrstuv The text length is dymanic (but always more than 17)...it can even span upto... (2 Replies)
Discussion started by: n_rajitr
2 Replies

3. Shell Programming and Scripting

Remove zero bytes files in folder

Hi, Please shed some light on how to quickly remove all the zero bytes in which there are some mixtures of more than zero bytes in it. For eg: > ls -lrt -rw-r--r-- 1 ab noen 0 Jul 27 15:47 supplier_mp.unl -rw-rw-r-- 1 ab noen 507 Aug 5 14:13... (2 Replies)
Discussion started by: cedrichiu
2 Replies

4. UNIX for Dummies Questions & Answers

Bytes of character in file

Hi, How do I check for the total bytes of character used by a file? Can I used a od command to check? Thanks. (1 Reply)
Discussion started by: user50210
1 Replies

5. Shell Programming and Scripting

Error PHP Fatal error: Allowed memory size of 67108864 bytes exhausted(tried to allocate 401 bytes)

While running script I am getting an error like Few lines in data are not being processed. After googling it I came to know that adding such line would give some memory to it ini_set("memory_limit","64M"); my input file size is 1 GB. Is that memory limit is based on RAM we have on... (1 Reply)
Discussion started by: elamurugu
1 Replies

6. Programming

Copying 1024 bytes data in 3-bytes chunk

Hi, If I want to copy a 1024 byte data stream in to the target location in 3-bytes chunk, I guess I can use the following script. dd bs=1024 count=3 if=/src of=/dest But, I would like to know, how to do it via a C program. I have tried this with memcpy(), that did not help. (3 Replies)
Discussion started by: royalibrahim
3 Replies

7. UNIX for Dummies Questions & Answers

X bytes of 0, Y bytes of random data, Z bytes of 5, T bytes of 1. ??

Hello guys. I really hope someone will help me with this one.. So, I have to write this script who: - creates a file home/student/vmdisk of 10 mb - formats that file to ext3 - mounts that partition to /mnt/partition - creates a file /mnt/partition/data. In this file, there will... (1 Reply)
Discussion started by: razolo13
1 Replies

8. Shell Programming and Scripting

Shell script - entered input(1-40 bytes) needs to be converted exactly 40 bytes

hello, suppose, entered input is of 1-40 bytes, i need it to be converted to 40 bytes exactly. example: if i have entered my name anywhere between 1-40 i want it to be stored with 40 bytes exactly. enter your name: donald duck (this is of 11 bytes) expected is as below - display 11... (3 Replies)
Discussion started by: shravan.300
3 Replies

9. Shell Programming and Scripting

Get file's first x bytes

is there a better way to do this: head -c 10000k /var/dump.log | head -c 6000k unfortunately, the "-c" option is not available on sun solaris. so i'm looking at "dd". but i dont know how to use it to achieve the same exact goal as the above head command. this needs to work on both solaris... (5 Replies)
Discussion started by: SkySmart
5 Replies

10. Shell Programming and Scripting

Extract sequences of bytes from binary for differents blocks

Hello to all, I would like to search sequences of bytes inside big binary file. The bin file contains blocks of information, each block begins is estructured as follow: 1- Each block begins with the hex 32 (1 byte) and ends with FF. After the FF of the last block, it follows 33. 2- Next... (59 Replies)
Discussion started by: Ophiuchus
59 Replies
Tcl_ByteArrayObj(3)					      Tcl Library Procedures					       Tcl_ByteArrayObj(3)

__________________________________________________________________________________________________________________________________________________

NAME
Tcl_NewByteArrayObj, Tcl_SetByteArrayObj, Tcl_GetByteArrayFromObj, Tcl_SetByteArrayLength - manipulate Tcl objects as a arrays of bytes SYNOPSIS
#include <tcl.h> Tcl_Obj * Tcl_NewByteArrayObj(bytes, length) void Tcl_SetByteArrayObj(objPtr, bytes, length) unsigned char * Tcl_GetByteArrayFromObj(objPtr, lengthPtr) unsigned char * Tcl_SetByteArrayLength(objPtr, length) ARGUMENTS
const unsigned char *bytes (in) The array of bytes used to initialize or set a byte-array object. int length (in) The length of the array of bytes. It must be >= 0. Tcl_Obj *objPtr (in/out) For Tcl_SetByteArrayObj, this points to the object to be converted to byte-array type. For Tcl_GetByteArrayFromObj and Tcl_SetByteArrayLength, this points to the object from which to get the byte-array value; if objPtr does not already point to a byte-array object, it will be converted to one. int *lengthPtr (out) If non-NULL, filled with the length of the array of bytes in the object. _________________________________________________________________ DESCRIPTION
These procedures are used to create, modify, and read Tcl byte-array objects from C code. Byte-array objects are typically used to hold the results of binary IO operations or data structures created with the binary command. In Tcl, an array of bytes is not equivalent to a string. Conceptually, a string is an array of Unicode characters, while a byte-array is an array of 8-bit quantities with no implicit meaning. Accessor functions are provided to get the string representation of a byte-array or to convert an arbitrary object to a byte- array. Obtaining the string representation of a byte-array object (by calling Tcl_GetStringFromObj) produces a properly formed UTF-8 sequence with a one-to-one mapping between the bytes in the internal representation and the UTF-8 characters in the string representation. Tcl_NewByteArrayObj and Tcl_SetByteArrayObj will create a new object of byte-array type or modify an existing object to have a byte-array type. Both of these procedures set the object's type to be byte-array and set the object's internal representation to a copy of the array of bytes given by bytes. Tcl_NewByteArrayObj returns a pointer to a newly allocated object with a reference count of zero. Tcl_SetByteAr- rayObj invalidates any old string representation and, if the object is not already a byte-array object, frees any old internal representa- tion. Tcl_GetByteArrayFromObj converts a Tcl object to byte-array type and returns a pointer to the object's new internal representation as an array of bytes. The length of this array is stored in lengthPtr if lengthPtr is non-NULL. The storage for the array of bytes is owned by the object and should not be freed. The contents of the array may be modified by the caller only if the object is not shared and the call- er invalidates the string representation. Tcl_SetByteArrayLength converts the Tcl object to byte-array type and changes the length of the object's internal representation as an array of bytes. If length is greater than the space currently allocated for the array, the array is reallocated to the new length; the newly allocated bytes at the end of the array have arbitrary values. If length is less than the space currently allocated for the array, the length of array is reduced to the new length. The return value is a pointer to the object's new array of bytes. SEE ALSO
Tcl_GetStringFromObj, Tcl_NewObj, Tcl_IncrRefCount, Tcl_DecrRefCount KEYWORDS
object, byte array, utf, unicode, internationalization Tcl 8.1 Tcl_ByteArrayObj(3)
All times are GMT -4. The time now is 07:00 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy