Results 1 to 4 of 4
I'm trying to clean up a DB load file. The file contains a delimiter sequence of '|~' and I need to change it to 5 (the micro symbol).
XBFTFieldDelim="|~"
fieldDelim="5"
...
- 07-21-2008 #1Just Joined!
- Join Date
- Jul 2008
- Posts
- 2
Sed translation of octal characters
I'm trying to clean up a DB load file. The file contains a delimiter sequence of '|~' and I need to change it to \265 (the micro symbol).
XBFTFieldDelim="|~"
fieldDelim="\265"
sed -e "s/$XBFTFieldDelim/$fieldDelim/g" data.load
The error I'm getting is:
sed: -e expression #1, char 11: Invalid reference \2 on `s' command's RHS
I've tried a lot variations on the command with no success.
No one at work will give me any help.
Mark
- 07-22-2008 #2
This is in a bash script, right?
Hope this helps.Code:#!/bin/bash XBFTFieldDelim="|~" fieldDelim=$(echo -e "\xb5") sed -e "s/$XBFTFieldDelim/$fieldDelim/g" data.load
--
Bill
Old age and treachery will overcome youth and skill.
- 07-22-2008 #3Linux User
- Join Date
- Aug 2006
- Posts
- 458
if you have fields and field delimiters, its easier to work with them using awk
Code:awk 'BEGIN{FS="[|][~]"}{$1=$1}1' OFS="\265" file
- 07-22-2008 #4Just Joined!
- Join Date
- Jul 2008
- Posts
- 2
Thanks Bill, that worked. I tried something similar to that a few weeks ago, but obviously I did not do it right.
ghostdog74, I did not try the awk code since there are 3 different delimiters that require changing. The sed route seemed to be the most direct at my stage of understanding. I'll put down awk for more studying next month once project work eases up.
Mark


Reply With Quote