Monday, 5 March 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

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...