If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Change a . to a _ using sed

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-16-04, 10:57
TimoV TimoV is offline
Registered User
 
Join Date: Dec 2003
Posts: 56
Red face 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?
Reply With Quote
  #2 (permalink)  
Old 04-16-04, 11:26
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
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
Reply With Quote
  #3 (permalink)  
Old 04-16-04, 11:55
TimoV TimoV is offline
Registered User
 
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 11:59.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On