replace a character with another character


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting replace a character with another character
# 1  
Old 05-19-2008
Java 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  
Old 05-19-2008
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  
Old 05-19-2008
Quote:
Originally Posted by satish@123
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  
Old 05-19-2008
Code:
echo 'abc.ghi.jkl.mno.pqr' | tr '.' '_'

# 5  
Old 05-19-2008
If you are using bash or ksh93
Code:
$ var=abc.ghi.jkl.mno.pqr
$ result=${var//./_}
$ echo $result
abc_ghi_jkl_mno_pqr

# 6  
Old 05-13-2009
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  
Old 05-13-2009
oh sorry.
I mean to say.
$ echo $oldpath1

oldpath1 is null.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed searches a character string for a specified delimiter character, and returns a leading or traili

Hi, Anyone can help using SED searches a character string for a specified delimiter character, and returns a leading or trailing space/blank. Text file : "1"|"ExternalClassDEA519CF5"|"Art1" "2"|"ExternalClass563EA516C"|"Art3" "3"|"ExternalClass305ED16B8"|"Art9" ... ... ... (2 Replies)
Discussion started by: fspalero
2 Replies

2. UNIX for Advanced & Expert Users

Replace certain character at specific place with related character

hello i have file with 100k records and each one has certain value that starts at 28th column and certain value that starts at 88th column e.g. 1st file <25>1234567 ..... <88> 8573785485 i have aditional file with values which are related to value that starts at 88th column of the... (1 Reply)
Discussion started by: dell1520
1 Replies

3. Shell Programming and Scripting

Find character and Replace character for given position

Hi, i want find the character '-' in a file from position 284-298, if it occurs i need to replace it with 'O ' for the position in the file. How to do that using SED command. thanks in advance, Sara (9 Replies)
Discussion started by: Sara183
9 Replies

4. Shell Programming and Scripting

Replace multiple occurances of same character with a single character.

Hi all, Greetings, I have the following scenario, The contents of main file are like : Unix|||||forum|||||||||||||||is||||||the||best so||||||be|||||on||||||||||||||||||||||||||||||||||||||||||||it And i need the output in the following form: Unix=forum=is=the=best so=be=on=it ... (3 Replies)
Discussion started by: dipanchandra
3 Replies

5. Shell Programming and Scripting

In Sed how can I replace starting from the 7th character to the 15th character.

Hi All, Was wondering how I can do the following.... I have a String as follows "ACCTRL000005022RRWDKKEEDKDD...." This string can be in a file called tail.out or in a Variable called $VAR2 Now I have another variable called $VAR1="000004785" (9 bytes long), I need the content of... (5 Replies)
Discussion started by: mohullah
5 Replies

6. Shell Programming and Scripting

Replace 2 Character With One Using tr

Hi, I have an XML file which is all on one line. <?xml version="1.0" encoding="utf-8"?><FUNCTION><PRODUCTS><PRODUCT CODE="PROD1" ACTION="amend" VALIDATE="no"><SUPPLIER PRODUCT="SUPPPROD1" ACTION="amend" CODE="SUPPLIER"><STOCK_QUANTITY DATA="291"></STOCK_QUANTITY> <STOCK_DATE... (3 Replies)
Discussion started by: Ste_Moore01
3 Replies

7. Shell Programming and Scripting

read the text file and print the content character by character..

hello all i request you to give the solution for the following problem.. I want read the text file.and print the contents character by character..like if the text file contains google means..i want to print g go goo goog googl google like this Using unix Shell scripting... without using... (1 Reply)
Discussion started by: samupnl
1 Replies

8. UNIX for Advanced & Expert Users

if 4th and 5th character of sting -ge 45 then add 1 to 3rd character

I want to know how to, given a string like W87151WR71C, if the 4th and 5th character (in this case 15) are greater than 45, then to add 1 to the 3rd character (in this case 7) and assign the revised string the variable name MODSTRING. Thanks in advance. This is ultimately to grab info from... (6 Replies)
Discussion started by: glev2005
6 Replies

9. Shell Programming and Scripting

Deleting all characters from 350th character to 450th character from the log file

Hi All, I have a big log file i want to delete all characters (between 350th to 450th characters) starting at 350th character position to 450th character position. please advice or sample code. (6 Replies)
Discussion started by: rajeshorpu
6 Replies

10. Shell Programming and Scripting

read in a file character by character - replace any unknown ASCII characters with spa

Can someone help me to write a script / command to read in a file, character by character, replace any unknown ASCII characters with space. then write out the file to a new filename/ Thanks! (1 Reply)
Discussion started by: raghav525
1 Replies
Login or Register to Ask a Question