Issue
i have a problem with my sed command. I have the following file and want to replace line number 4.
text.txt content:
1 Hi World!
2 Okey
3 Test
4 ;date.timezone =
cmd command:
sed -i -e "s/;date.timezone =/date.timezone = Europe/Berlin/" text.txt
Because my replacement holds a / inside, the sed command cant execute properly because of Europe/Berlin
.
My Folder Structure:
folder structrure
/Users/user/dev/repos/docker
└── text.txt
My fix would be to ignore the / between Europe and Berlin. I didn't really find the answer in the web, that's why I reach out for you?
Output:
sed: 1: "s/;date.timezone =/date ...": bad flag in substitute command: 'B'
Solution
You can use any separator in the sed command terms.
I usually use #
in these cases. For instance this should work:
sed -i -e "s#;date.timezone =#date.timezone = Europe/Berlin#" text.txt
Answered By - Gonzalo Matheu Answer Checked By - Senaida (WPSolving Volunteer)