Sponsored Content
Top Forums Shell Programming and Scripting Edit file hexadecimal with xxd Post 302965992 by wisecracker on Friday 5th of February 2016 06:33:10 PM
Old 02-05-2016
Not sure if this is what is required...
Shell builtins around xxd as xxd has some strange quirks in spitting out a pure hexdump...
OSX 10.7.5 default bash terminal.
Code:
#¡/bin/bash
# bin_edit
# Create a working binary file...
echo ""
BIN_ARRAY=( 00 00 00 00 00 00 00 00 00 00 00 00 49 3a 00 4f 63 74 20 32 38 20 32 30 31 35 20 31 39 3a 32 34 )
for n in {0..31} 
do
	echo -en "\x${BIN_ARRAY[$n]}"
done > /tmp/bin
# Prove binary exists...
xxd /tmp/bin
# Now create the edit...
HEX=( $( xxd -cols 1 -p /tmp/bin ) )
# Now edit...
NEWHEX=""
for n in $( seq 0 2 ${#HEX[@]} )
do
	OLDHEX="${HEX[$n]}${HEX[$(($n+1))]}"
	if [ "$OLDHEX" = "493a" ]
	then
		:
	else
		echo -en "$NEWHEX$OLDHEX"
	fi
done > /tmp/texthexdump
echo ""
# 0x493a now removed creating new binary file...
read -r line < /tmp/texthexdump
n=0
while [ $n -lt ${#line} ]
do
	echo -en "\x${line:$n:2}"
	n=$(($n+2))
done > /tmp/newbin
xxd /tmp/newbin
echo ""

Results:-
Code:
Last login: Fri Feb  5 22:34:02 on ttys000
AMIGA:barrywalker~> cd Desktop/Code/Shell
AMIGA:barrywalker~/Desktop/Code/Shell> ./bin_edit

0000000: 0000 0000 0000 0000 0000 0000 493a 004f  ............I:.O
0000010: 6374 2032 3820 3230 3135 2031 393a 3234  ct 28 2015 19:24

0000000: 0000 0000 0000 0000 0000 0000 004f 6374  .............Oct
0000010: 2032 3820 3230 3135 2031 393a 3234        28 2015 19:24

AMIGA:barrywalker~/Desktop/Code/Shell> _

This will take out ALL '493a' on even addresses only but odd adresses can be catered for.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get Hexadecimal Value

I have a record in a file that ends with the new line character "\n". How dio I determine the hexadecimal value for that? (2 Replies)
Discussion started by: lesstjm
2 Replies

2. UNIX for Dummies Questions & Answers

edit a .fs file

I have a .fs file that I want to edit, (or just be able to see what is in it) preferably through a windows environment. Does anyone know how to do that? Thanks (4 Replies)
Discussion started by: kiterboy
4 Replies

3. Shell Programming and Scripting

Edit value in File

I have a file oratab with entry like this SCADAG:/esitst1/oracle/product/9.2.0.8:Y I am trying to discover a way to change the 9.2.0.8 part of this to something like 10.2.0.4 as part of an upgrade script. I have tried cat /etc/oratab >>/tmp/oratab... (1 Reply)
Discussion started by: sewood
1 Replies

4. UNIX for Dummies Questions & Answers

Hexadecimal to Decimal

Hi all, I have a small script to convert my HexaDecimal Input to Decimal as output. #!/bin/ksh hd=00208060 dec=`printf %d $hd` echo $dec Output of the above program: printf: 00208060 not completely converted 16 But my expected output is "2130016". How can i acheive this. I... (2 Replies)
Discussion started by: Arunprasad
2 Replies

5. Shell Programming and Scripting

Script to Edit the file content and create new file

I have a requirement, which is as follows *. Folder contains list of xmls. Script has to create new xml files by copying the existing one and renaming it by appending "_pre.xml" at the end. *. Each file has multiple <Name>fileName</Name> entry. The script has to find the first occurance of... (1 Reply)
Discussion started by: sudesh.ach
1 Replies

6. Programming

Hexadecimal to ascii

Let's suppose i have a hexadecimal array with 16 cells.for example b3e2d5f636111780 i want to convert it to an array of ascii characters(in C) so that i can reduce total size of the file i want to put it in. But i am afraid i have not fully understand the difference between ascii and hex(i... (3 Replies)
Discussion started by: bashuser2
3 Replies

7. Shell Programming and Scripting

Reverse hexdump without xxd

The "hexdump" command cannot perform reverse operation. On the other hand, the "xxd" command with -r option performs reverse hexdump, while the "xxd" command without -r performs the (forward) hexdump. An example of hexdump is to convert ABCD into 41 42 43 44. An example of reverse hexdump is to... (3 Replies)
Discussion started by: LessNux
3 Replies

8. HP-UX

Editing a UNIX file in Hexadecimal format

Hi, I am a newbie to the UNIX world. I am asked to edit the file in hexadecimal format and save it. Later I should be able to print the file in char mode. please anyone tell me how to do that mostly using VI editor. (1 Reply)
Discussion started by: vkudire
1 Replies

9. Shell Programming and Scripting

To convert file with decimal to another file with Hexadecimal

I have a text file of alphanumeric values listed one by one. I have to convert them to hexadecimal equivalents for each character seperated by ":" in Unix bash shell script. For example, 12345678 has to be converted to 31:32:33:34:35:36:37:38 (10 Replies)
Discussion started by: mathie
10 Replies

10. Shell Programming and Scripting

Generate hexadecimal

Hello I'm working on a script to list all ipv6 from given address so I've run this script which create hex part of ipv6 STR2=159 END2=200 SUM2=`expr $END2 - $STR2` for ((i=STR2;i<=END2;++i)); do x=$( printf "%x" $i ) ; echo $x echo -e "::"$x >> netpart.txt done output is : ::9f... (2 Replies)
Discussion started by: nimafire
2 Replies
mlib_VideoColorUYV444int_to_ARGBint(3MLIB)		    mediaLib Library Functions			mlib_VideoColorUYV444int_to_ARGBint(3MLIB)

NAME
mlib_VideoColorUYV444int_to_ARGBint - color convert UYV interleaved to ARGB interleaved SYNOPSIS
cc [ flag... ] file... -lmlib [ library... ] #include <mlib.h> void mlib_VideoColorUYV444int_to_ARGBint(mlib_u32 *ARGB, const mlib_u8 *UYV, const mlib_u8 *A_array, mlib_u8 A_const, mlib_s32 w, mlib_s32 h, mlib_s32 dlb, mlib_s32 slb, mlib_s32 alb); DESCRIPTION
The UYV pixel stream is converted into an ARGB pixel stream. All pixel components are 8-bit unsigned integers. All buffers have dimensions w and h. The alpha values for this function work in the following fashion: o If A_array pointer is not NULL, the values are taken from there. It has to have the same dimensions as the Y buffer. o If A_array pointer is NULL, the alpha values for every pixel are set to A_const. The following equation is used: |R| |1.1644 0.0000 1.5966| [|Y| | 16.0000|] |G| = |1.1644 -0.3920 -0.8132| * [|U| - |128.0000|] |B| |1.1644 2.0184 0.0000| [|V| |128.0000|] PARAMETERS
The function takes the following arguments: ARGB Pointer to output buffer. UYV Pointer to input buffer. A_array Array of alpha values. A_const Constant alpha value. w Image width in pixels. h Image height in lines. dlb Linebytes for output buffer. slb Linebytes for input buffer. alb Linebytes for alpha buffer. RETURN VALUES
None. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Evolving | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ SEE ALSO
mlib_VideoColorYUV420seq_to_ARGBint(3MLIB), mlib_VideoColorYUV411seq_to_ARGBint(3MLIB), mlib_VideoColorYUV422seq_to_ARGBint(3MLIB), mlib_VideoColorYUV444seq_to_ARGBint(3MLIB), mlib_VideoColorYUV420seq_to_ABGRint(3MLIB), mlib_VideoColorYUV411seq_to_ABGRint(3MLIB), mlib_VideoColorYUV422seq_to_ABGRint(3MLIB), mlib_VideoColorYUV444seq_to_ABGRint(3MLIB), mlib_VideoColorYUYV422int_to_ARGBint(3MLIB), mlib_VideoColorYUV444int_to_ARGBint(3MLIB), mlib_VideoColorYUYV422int_to_ABGRint(3MLIB), mlib_VideoColorYUV444int_to_ABGRint(3MLIB), mlib_VideoColorUYVY422int_to_ARGBint(3MLIB), mlib_VideoColorUYVY422int_to_ABGRint(3MLIB), mlib_VideoColorUYV444int_to_ABGRint(3MLIB), attributes(5) SunOS 5.10 10 Nov 2004 mlib_VideoColorUYV444int_to_ARGBint(3MLIB)
All times are GMT -4. The time now is 08:41 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy