Monday, March 5, 2018

sed - Replace string in linux bash




I am writing a bash script for installing django with postgresql database automatically.
Now , I want to replace database name by command ,since it is using sqlite3 database file path.



I wrote this command:




sudo sed -i 's/os.path.join(BASE_DIR, 'db.sqlite3'),/'$project_name',/g' $projects_name/settings.py


But this is not changed while I am making the django project.



How to change this , please help me.


Answer



Use double-quotes around sed for variable expansion & to preserve single quotes.




sed -i "s/os.path.join(BASE_DIR, 'db.sqlite3'),/$project_name,/g" "$project_name/settings.py"


tested working fine on GNU sed version 4.2.1


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...