Rohan Gala
Rohan Gala

Reputation: 651

sed not working correctly when using variables

source=<!--jta-data-source>jdbc/FCBDataSource</jta-data-source-->

destination=<jta-data-source>jdbc/FCBDataSource</jta-data-source>


sed -i "s/$source/$destination/g" /home/rohan/R2.5LZN/UIReleasedArea/obp.ui.domain/persistence.xml

I am getting error sed: -e expression #1, char 44: unknown option to s

Upvotes: 2

Views: 292

Answers (2)

200_success
200_success

Reputation: 7582

Consider what happens when the substitution occurs. The command becomes:

sed -i 's/<!--jta-data-source>jdbc/FCBDataSource</jta-data-source-->/<jta-data-source>jdbc/FCBDataSource</jta-data-source>/g' some_filename

Then, sed sees s/<!--jta-data-source>jdbc/FCBDataSource</j… and thinks that you want to replace an occurrence of <!--jta-data-source>jdbc with the text FCBDataSource<, and the s command has an illegal j modifier (and other junk).

You need to pick a delimiter character that does not appear in either the pattern or the replacement text. A , will do.

Upvotes: 1

Rohan Gala
Rohan Gala

Reputation: 651

destination='<!--jta-data-source>jdbc/FCBDataSource</jta-data-source-->'
source='<jta-data-source>jdbc/FCBDataSource</jta-data-source>'


sed -i "s,$source,$destination,g"     
/home/rohan/R2.5LZN/UIReleasedArea/obp.ui.domain/persistence.xml

The problem was with the variable

Quotes were required

Upvotes: 0

Related Questions