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 here.

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

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-18-2008
Registered User
 

Join Date: Mar 2007
Posts: 31
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
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-18-2008
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.
Reply With Quote
  #3 (permalink)  
Old 05-18-2008
Registered User
 

Join Date: Dec 2006
Posts: 28
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'
Reply With Quote
  #4 (permalink)  
Old 05-19-2008
agn agn is offline
Registered User
 

Join Date: Feb 2008
Posts: 76
Code:
echo 'abc.ghi.jkl.mno.pqr' | tr '.' '_'
Reply With Quote
  #5 (permalink)  
Old 05-19-2008
Moderator
 

Join Date: Dec 2003
Location: /ksh93
Posts: 849
If you are using bash or ksh93
Code:
$ var=abc.ghi.jkl.mno.pqr
$ result=${var//./_}
$ echo $result
abc_ghi_jkl_mno_pqr
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:55 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0