Replace characters between $ and . with .


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace characters between $ and . with .
# 1  
Old 01-12-2017
Replace characters between $ and . with .

Hi -
I have below in put to demo.txt

Code:
/test/xyz/ibcdownload.jsp
/test/xyz/pvxprogramtreeovermain.jsp
/test/xyz/jtfrsrsr$HtmlTag.jsp
/test/xyz/csdronumlov.jsp
/test/xyz/iecvaluereset.jsp
/test/xyz/ibecumpassignrole.jsp
/test/xyz/ozfoffermarketmain.jsp

output should be
/test/xyz/ibcdownload.jsp
/test/xyz/pvxprogramtreeovermain.jsp
/test/xyz/jtfrsrsr.jsp
/test/xyz/csdronumlov.jsp
/test/xyz/iecvaluereset.jsp
/test/xyz/ibecumpassignrole.jsp
/test/xyz/ozfoffermarketmain.jsp

I am trying
HTML Code:
sed "s/\$\*\./\./g"
is not working for me.
either all character and lines are replaced or it says pattern doesnt match.

I tried online but was not able to get it working.

Appreciate any help..
Thanks,
# 2  
Old 01-12-2017
Any number of characters: .*
Code:
sed "s/$.*\././"

Only the literal . needs a \ escape.
The literal $ can have one for clarity, but then I'd put the sed script in 'ticks'.
Code:
sed 's/\$.*\././'

This User Gave Thanks to MadeInGermany For This Post:
# 3  
Old 01-12-2017
Quote:
Originally Posted by MadeInGermany
Any number of characters: .*
Code:
sed "s/$.*\././"

Only the literal . needs a \ escape.
The literal $ can have one for clarity, but then I'd put the sed script in 'ticks'.
Code:
sed 's/\$.*\././'

I tried below worked for me.
Code:
sed 's/$.*/.jsp/g'


Not sure if it has any edge cases. Thanks for reply.
# 4  
Old 01-12-2017
Quote:
Originally Posted by oraclermanpt
I tried below worked for me.
Code:
sed 's/$.*/.jsp/g'


Not sure if it has any edge cases. Thanks for reply.
This works only once per line, so the g can be left out.
Code:
sed 's/$.*/.jsp/'

to make it work one or more time per line, you could try:
Code:
sed 's/$[^.]*//g'

This User Gave Thanks to Scrutinizer For This Post:
# 5  
Old 01-12-2017
No edge cases. You put back what you matched too much.
--
The /g option for multi-substituion on the same line is not needed:
Code:
echo 'aaaa$bbbb.cccc$dddd.eeee' | sed 's/\$.*\././'
echo 'aaaa$bbbb.cccc$dddd.eeee' | sed 's/\$.*\././g'

give the same result, because of the greedy .* match
You only see a multi-substitution effect with a minimum match
Code:
echo 'aaaa$bbbb.cccc$dddd.eeee' | sed 's/\$[^.]*\././'
echo 'aaaa$bbbb.cccc$dddd.eeee' | sed 's/\$[^.]*\././g'

This User Gave Thanks to MadeInGermany For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to replace all but the first 3 characters with sed?

This seems like it should be an easy problem, but for some reason I am struggling with the solution. I simply want to replace all characters after the first 3 characters with another character, preferably with sed. Thanks in advance. Like this, but producing the proper number of *'s: sed... (30 Replies)
Discussion started by: leolson
30 Replies

2. Shell Programming and Scripting

Replace special characters with Escape characters?

i need to replace the any special characters with escape characters like below. test!=123-> test\!\=123 !@#$%^&*()-= to be replaced by \!\@\#\$\%\^\&\*\(\)\-\= (8 Replies)
Discussion started by: laknar
8 Replies

3. Shell Programming and Scripting

Replace special characters

I have a line ending with special character and 0 The special character is the field separator for this line in VI mode the file will look like below, but while cat the special character wont display i know the hexa code for the special character ^_ is \x1f and ascii code is \0037, ... (0 Replies)
Discussion started by: ratheeshjulk
0 Replies

4. Solaris

How to replace special characters in vi?

Hi , I want to replace the special characters in the file. For eg: cat abc 1234/4455/acb 234/k/lll/ 234`fs`fd I want to replace / and ` with the letter a and the output should like below. How to achieve this. 1234a4455aacb 234akallla 234afsafd (2 Replies)
Discussion started by: rogerben
2 Replies

5. Shell Programming and Scripting

how to replace characters using tr

Hi, I have a file which includes some French Characters and I want to change them to other characters like À to &Agrave; Â to &Acirc; É to &Eacute; ..... ..... and so on. I am tyring to use tr command like tr ÀÂÉ &Agrave;&Acirc;&Eacute; < input file But it does not work. Only... (2 Replies)
Discussion started by: naveed
2 Replies

6. Shell Programming and Scripting

How to replace characters with random characters

I've got a file (numbers.txt) filled with numbers and I want to replace each one of those numbers with a new random number between 0 and 9. This is my script so far: #!/bin/bash rand=$(($RANDOM % 9)) sed -i s//$rand/g numbers.txtThe problem that I have is that it replaces each number with just... (2 Replies)
Discussion started by: hellocatfood
2 Replies

7. Shell Programming and Scripting

replace characters in a file

Hi, I have a file in which i want to replace the charaters from position 3-5 with a particular string for the first line. For ex The file contains abcdefghij jkdsflsfkdk 908090900 i want to replace the characters 3-5 for the first line as 678 so, the file should look like ... (7 Replies)
Discussion started by: dnat
7 Replies

8. Shell Programming and Scripting

replace UTF-8 characters with tr

Hi, I try to get tr to replace multibytes characters by ascii equivalent. For example "Je vais à l'école" ---> 'Je vais a l'ecole" But my version of tr (5.97) doesn't seem to support multibyte sets. $ locale charmap; echo "Je vais à l'école" | tr éà ea UTF-8 Je vais aa l'aacole I try to... (2 Replies)
Discussion started by: ripat
2 Replies

9. Shell Programming and Scripting

Want to replace characters

Hi I have searched for a way to replace odd characters in a FOLDER NAME. All search-and-replace issues I have seen, only involves how to make search-and-replace on a FILE och with TEXT INSIDE a FILE. My problem is with the FOLDER NAME. My case is this: I have a couple of persons that every... (5 Replies)
Discussion started by: arndorff
5 Replies

10. UNIX for Dummies Questions & Answers

Replace Characters...

In a file, How do I replace a set number of characters in each line? For example.... substitute the first 54 characters of each line with mv? Thanks! Lisa (8 Replies)
Discussion started by: lgardner17325
8 Replies
Login or Register to Ask a Question