Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2003
    Posts
    56

    Red face Unanswered: Change a . to a _ using sed

    I have been building a little script that add/removes mksysb images from my nim server.

    Part of what it needs to do is resolve if a file (server.mksysb.date) is known as a NIM resource (server_mksysb_date). To do this I wrote the following bit of KSH code:

    Code:
    for i in 'ls ${DIR}/*.mksysb.*'
    do
       FILENAME='basename ${i}'
       NIMNAME='echo ${FILENAME} | sed s/\./_/g'
       "Do some nim bits....."
    
    done
    However my sed command did something I can explain but not what I expected...the $NIMNAME is changed into "_________" (an underscore for every character in the $FILENAME.

    Is there a way to change just the . to a _ and not every char?

  2. #2
    Join Date
    Jun 2002
    Location
    UK
    Posts
    525

    Re: Change a . to a _ using sed

    Enclose your sed command in quotes. In your example the shell is evaluating '\.' to '.' before sed even knows about it!

    Code:
    NIMNAME=`echo ${FILENAME} | sed 's/\./_/g'`
    (and I'm assuming that the single quotes instead of backticks was a typo)

    Damian

  3. #3
    Join Date
    Dec 2003
    Posts
    56
    Thanx! And yes that was a typo..switching between my sun keyboard and my windows machine with a "normal" keyboard still trips me up
    Last edited by TimoV; 04-16-04 at 12:59.

Posting Permissions

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