The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help to replace character strings rahulrathod UNIX for Dummies Questions & Answers 5 12-18-2008 05:26 AM
replace first character of string sed prkfriryce Shell Programming and Scripting 6 08-03-2007 03:07 PM
Replace a character in last line Mohammed Shell Programming and Scripting 6 08-01-2007 03:46 PM
How to replace a character in a file preethgideon Shell Programming and Scripting 6 08-30-2006 07:19 PM
replace character with tr tmxps UNIX for Dummies Questions & Answers 3 09-29-2005 08:32 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-19-2008
satish@123 satish@123 is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 35
Post replace a character with another character

hi
i have a string var=abc.ghi.jkl.mno.pqr
now i need to replace .(dot) with _(underscore)
the result should be like "arresult=abc_def_ghi_jkl_mno_pqr"

Please help
  #2 (permalink)  
Old 05-19-2008
yhacks yhacks is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 21
try this

echo $var | sed 's/\./_/g' -> will print the variable

x=`echo $var | sed 's/\./_/g'` will get the output into x variable.
  #3 (permalink)  
Old 05-19-2008
elthox elthox is offline
Registered User
  
 

Join Date: Dec 2006
Posts: 30
Quote:
Originally Posted by satish@123 View Post
hi
i have a string var=abc.ghi.jkl.mno.pqr
now i need to replace .(dot) with _(underscore)
the result should be like "arresult=abc_def_ghi_jkl_mno_pqr"

Please help
echo $var|sed 's/\./\_/g'
  #4 (permalink)  
Old 05-19-2008
agn agn is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 172

Code:
echo 'abc.ghi.jkl.mno.pqr' | tr '.' '_'

  #5 (permalink)  
Old 05-19-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,934
If you are using bash or ksh93

Code:
$ var=abc.ghi.jkl.mno.pqr
$ result=${var//./_}
$ echo $result
abc_ghi_jkl_mno_pqr

  #6 (permalink)  
Old 05-13-2009
nileshjori nileshjori is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 3
hi,

I want to replace _ with \_.
I am using below command.
echo old_path | sed 's/\_/\\_/g'

It is working fine.
but when I use that in script file like below.
$oldpath1=`echo old_path | sed 's/\_/\\_/g' > 1`;
$ echo oldpath1
oldpath1

It is not repacing.
Any suggestions.

Thanx in advance.
  #7 (permalink)  
Old 05-13-2009
nileshjori nileshjori is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 3
oh sorry.
I mean to say.
$ echo $oldpath1

oldpath1 is null.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:32 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0