replace character with tr | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

replace character with tr

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 09-28-2005
tmxps's Avatar
tmxps tmxps is offline
Registered User
 
Join Date: Sep 2005
Last Activity: 2 November 2005, 5:11 PM EST
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
replace character with tr

Hi,

i would like substitute the words containing the character "-" by any other.

i've already tried the tr command: tr '[a-z]\-[a-z]' '[a-z]X[a-z]', for example.

But, this command doesn't work. It gave this:

Original text:
-i abcd-fe

Result text:
Xi abcdXfe

Result desired:
-i abcdXfe

Thanks!
Sponsored Links
    #2  
Old 09-28-2005
mgirinath mgirinath is offline
Registered User
 
Join Date: May 2005
Last Activity: 3 November 2008, 2:18 PM EST
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
replace character

There are many ways to do it you can use sed or you can use tr as you wanted it for tr here is the code
suppose you have the text in test.txt file "-i abcd-fe"
then the command is
tr '-' 'X' <test.txt

enjoy....
Sponsored Links
    #3  
Old 09-28-2005
tmxps's Avatar
tmxps tmxps is offline
Registered User
 
Join Date: Sep 2005
Last Activity: 2 November 2005, 5:11 PM EST
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
yes ok, but that makes a substitution on all the charaters that tr find.

i only want to substitute the cases that the character '-' is between letters.

Thanks.
    #4  
Old 09-29-2005
monsanbu monsanbu is offline
Registered User
 
Join Date: Sep 2005
Last Activity: 3 November 2005, 10:42 PM EST
Location: Chennai,India
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
try the below sed command

echo "-i abcd-fe" | sed 's/-/X/2'
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Replace multiple occurances of same character with a single character. dipanchandra Shell Programming and Scripting 3 12-20-2010 01:17 AM
In Sed how can I replace starting from the 7th character to the 15th character. mohullah Shell Programming and Scripting 5 09-22-2010 08:39 PM
replace a character with another character satish@123 Shell Programming and Scripting 8 05-13-2009 03:04 PM
read in a file character by character - replace any unknown ASCII characters with spa raghav525 Shell Programming and Scripting 1 04-20-2009 01:52 PM
character replace pradeep_script Shell Programming and Scripting 3 01-10-2009 04:12 AM



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