👤
Home Man
Search
Today's Posts
Register

HP-UX (Hewlett Packard UniX) is Hewlett-Packard's proprietary implementation of the Unix operating system, based on System V.

Replacing Hex Characters In A File Using awk?

Tags
solved

👤 Login to reply

 
Thread Tools Search this Thread
# 8  
Old 04-28-2014
OK, it appears I have muddied the waters by only explaining what I think I need.

Given that my knowledge is poor at best i'll explain the whole problem to try and give it context which will hopefully help.

I have a file which contains a hex value of 01 at the beginning of each 'record' and a hex value of '03' at the end of each record.

Within each record there are several 'lines' of data that end with a hex value of '0D0A'

So the data would look like this (crlf signifies a carriage return/line feed)

Code:
^AHIcrlf
BYEcrlf
-}^C

If I look at it in a HEX viewer I see

Code:
01 48 49 0D 0A
42 59 45 0D 0A
2D 7D 03

The problem I have is that the application I need to put the file into has the following restrictions

- The ^A character(hex value of 01) needs to be replaced with a space(hex value 20). So, I want to replace hex 01 with hex 20

- The ^C character(hex value 03) needs to be replaced with a carriage return and two line feeds(hex values 0D 0A 0A). So, I want to replace hex 03 with hex 0D 0A 0A.

What I want to end up with is

Code:
20 48 49 0D 0A
42 59 45 0D 0A
2D 7D 0D 0A 0A

Hopefully that makes what i'm aiming for a little clearer and apologies for not being accurate enough initially.
# 9  
Old 04-28-2014
Looks like your file is form DOS/win ... Try first using dos2ux then tell us what is left that needs modification...
# 10  
Old 04-28-2014
Try:
Code:
awk '{gsub(/\001/,FS); gsub(/\003/,"\r\n\n")}1' file > newfile


Last edited by Scrutinizer; 04-28-2014 at 12:42 PM.. Reason: Added quote
# 11  
Old 04-29-2014
Quote:
Originally Posted by Scrutinizer
Try:
Code:
awk '{gsub(/\001/,FS); gsub(/\003/,"\r\n\n")}1' file > newfile

That worked like a charm thank you!
👤 Login to reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Replacing characters in a file rossi UNIX for Advanced & Expert Users 12 07-15-2014 04:27 PM
Replacing hex characters figaro UNIX for Dummies Questions & Answers 6 05-16-2011 12:51 PM
Replacing hex characters '\x0D' with '\x0D\x0A' paragkalra Shell Programming and Scripting 6 12-03-2009 10:42 PM
replacing characters with awk thoreman Shell Programming and Scripting 2 03-16-2009 12:38 PM
Translating/Replacing characters in a file FranzB Shell Programming and Scripting 3 01-30-2009 10:47 AM
replacing the characters in a file trichyselva UNIX for Dummies Questions & Answers 2 01-03-2008 07:02 AM
Help Replacing Characters in Flat File nelson553011 Shell Programming and Scripting 8 05-17-2007 11:57 AM
replacing few characters in a file purnakarthik UNIX for Dummies Questions & Answers 1 01-25-2007 04:17 PM
Hex characters of ascii file budrito HP-UX 2 08-10-2005 10:26 PM
Replacing all but last Hex characters in a text line BAH Shell Programming and Scripting 2 03-26-2004 03:00 AM


All times are GMT -4. The time now is 05:10 AM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
×
UNIX.COM Login
Username:
Password:  
Show Password