Replacing all but last Hex characters in a text line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replacing all but last Hex characters in a text line
# 1  
Old 03-23-2004
Replacing all but last Hex characters in a text line

I must remove hex characters 0A and 0D from several fields within an MS Access Table. Since I don't think it can be done in Access, I am trying here.
I am exporting a Table from Access (must be fixed length fields, I think, for my idea to work here) into a text format.
I then want to run a script that will replace all instances of hex 0A from the line .... except for the very last instance ... with some other character ... say a hex 7C
Example: If I have 20 fields within Access for a total export line length of 2000 characters, I want to replace all the hex 0A characters (which is a CR/LF character, I believe) from positions 1-1999 with hex 7C (which is shift-\).
Anybody have any creative ideas? I would very much appreciate it.
Brad

Smilie
# 2  
Old 03-23-2004
You could use the tr command :-

tr '\012' '\174' < filein | tr '\015' '\012' | unix2dos > fileout

Explanation of above code:-
- use tr on the file to convert all 0A to 7C
- pipe result into tr to convert all 0D to 0A
- pipe result into unix2dos to expand all 0A to 0A0D

Notes:-
- Input lines can be of any length.
- Transfer files in binary mode to prevent automatic conversion.
# 3  
Old 03-26-2004
Removing or Replacing CR/LF characters (hex 0D and 0A) in MS Access Memo/Text Fields

This is just an FYI to help anybody that might be in a similar situation. I did not have to write or execute any UNIX script to remove these troublesome CR/LF hex characters from the text in several fields in one of my MS Access tables.
First of all, the MS Access Table in question is actually linked via an ODBC connection to an MS SQL Server database.
After establishing the link and being able to view the data, I export the data using the tilde (~) as the delimiter and using the quote (") to surround text fields .... and save the file as a type .txt or.csv file. I made sure that the tilde did not exist in the Table prior to selecting it as my delimiter.
Once the export file was created, I used an awesome tool which I found and downloaded from the internet to edit out the CR/LF characters.
The hex editor tool used is called XVI32. Link provided here: http://www.chmaas.handshake.de/delph...vi32/xvi32.htm
Since MS Access also puts out CR/LF characters as it exports the data, I had to find some unique sequence of characters either from the end of the record ... or the beginning of the record that is on either side of the hex 0D 0A that MS Access puts at the end of each exported record. I then performed a hex replace of the sequence of characters with some other unique sequence of characters.
For example: the sequence of characters I found to be unique were: 73 65 71 75 65 6E 63 65 0D 0A
The 0D 0A shown here was actually put there by Access.
The tool allowed me to change this sequence to: 73 65 71 75 65 6E 63 65 7C 7C
I replaced the 0D 0A with a 7C 7C.
The hex 7C character (shift-\) did not previously exist in the Table either.
After that completed, I am then able to delete (or replace) any other occurrence of 0D or 0A that exist in the file .... i.e. the occurrences that I want to remove/replace that exist in the free text fields of the record.
Now, once that completed, I then change back the sequence of characters from 73 65 71 75 65 6E 63 65 7C 7C to 73 65 71 75 65 6E 63 65 0D 0A.
I then save the file (with a new name ... just 2B safe). I now have a .txt file that MS Access will be able to re-import correctly ... or just link to ... as desired.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Checking and replacing first line in text file, one-liner?

Hello, I'm looking to check only the first line of a file to see if it is a format string, like # -*- coding: utf-8; mode: tcl; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -\*- vim:fenc=utf-8:ft=tcl:et:sw=2:ts=2:sts=2if the first line is anything else, insert the above string. I'd... (3 Replies)
Discussion started by: f77hack
3 Replies

2. HP-UX

Replacing Hex Characters In A File Using awk?

Hi guys, First off, i'm a complete noob to UNIX and LINUX so apologies if I don't understand the basics! I have a file which contains a hex value of '0D' at the end of each line when I look at it in a hex viewer. I need to change it so it contains a hex value of '0D0A0A' I thought... (10 Replies)
Discussion started by: AndyBSG
10 Replies

3. Shell Programming and Scripting

Replacing end of line characters

Hello, I'm looking for some help in renaming data-timestamps stored within different calendar directories/files. The calendar directory has hundreds of ICS files: ~/Library/Calendars/F494C908.calendar/Events/92B65E439AAC.ics ~/Library/Calendars/F494C908.calendar/Events/DE7867E61969.ics... (8 Replies)
Discussion started by: Schubi
8 Replies

4. Shell Programming and Scripting

Replacing text in Perl given by command line

Hi I need to write a Perl script that the file given as first argument of the command line that will find all occurrences of the string given as the third argument of the command line and replace with the string given as the fourth argument. Name newfound file is specified as the second... (3 Replies)
Discussion started by: nekoj
3 Replies

5. Shell Programming and Scripting

Replacing text on every third line

I have file like this "copy table_name from filea.txt on node replace delimiter '|';" "copy table_name from fileb.txt on node replace delimiter '|';" "copy table_name from filec.txt on node replace delimiter'|';" "copy table_name from filee.txt on node replace delimiter '|';" "copy... (1 Reply)
Discussion started by: nnani
1 Replies

6. UNIX for Dummies Questions & Answers

Replacing hex characters

I have the following file consisting of dates and sample measurements: 05��Oct��2010 1.31�� 06��Oct��2010 1.32�� 07��Oct��2010 1.31�� The hex characters are \xc2\xa0 in sequence. I have tried to remove the characters as follows: sed -i '' -e 's/\xc2\xa0//g' file.dat and as follows... (6 Replies)
Discussion started by: figaro
6 Replies

7. Shell Programming and Scripting

Replacing text/characters in vi

ok, so i have the following text to replace but it's not working. can someone please help me out: :%s~awk '// {split($2,s,",");a=$1 FS s} /-/ {b=a} END{print b}'~tail -1~g I want to replace the entire awk command with tail -1. thanks (7 Replies)
Discussion started by: SkySmart
7 Replies

8. Shell Programming and Scripting

Replacing hex characters '\x0D' with '\x0D\x0A'

Hello All, I have a requirement where I need to replaced the hex character - '\x0D' with 2 hex characters - 'x0D' & 'x0A' I am trying to use SED - But somehow its not working. Any pointers? Also the hex character '\x0D' can occur anywhere in the line. Can this also be accomplished... (6 Replies)
Discussion started by: paragkalra
6 Replies

9. Shell Programming and Scripting

replacing certain characters with new line?

i have a text file which domains something like this 123213213213/32434342 324324324/12312321321 12321321,435435435 12321312 / 12313213 / 12435435345 4353213 , 123213213213 21321321312-12334324 234324324 - 235645645645 456456456 - 45456456456 - 45645645654243 how can i replace '/' and... (4 Replies)
Discussion started by: Bashar
4 Replies

10. Shell Programming and Scripting

Replacing characters in file with line break

Hi, Apologies if this has been asked before, but I searched and was not able to find an answer. It's probably a simple question to answer for those of you with some experience, though... I have a relatively long string where tokens are separated by the colon (':') character. Let's say the... (10 Replies)
Discussion started by: johnemb
10 Replies
Login or Register to Ask a Question