|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
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
|
|||
|
|||
|
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
|
||||
|
||||
|
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
|
|||
|
|||
|
try the below sed command
echo "-i abcd-fe" | sed 's/-/X/2' |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| 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 |
|
|