Find the answer to your Linux question:
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" ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just 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

  2. #2
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    This is in a bash script, right?
    Code:
    #!/bin/bash
    
    XBFTFieldDelim="|~"
    fieldDelim=$(echo -e "\xb5")
    
    sed -e "s/$XBFTFieldDelim/$fieldDelim/g" data.load
    Hope this helps.
    --
    Bill

    Old age and treachery will overcome youth and skill.

  3. #3
    Linux 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

  4. #4
    Just Joined!
    Join Date
    Jul 2008
    Posts
    2

    Thumbs up

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •