0

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'
leonms.dev
  • 33
  • 1
  • 8
  • 1
    Like this? `sed -i -e "s/;date\.timezone =/date.timezone = Europe\/Berlin\//" text.txt` – The fourth bird Dec 02 '22 at 14:59
  • Use an alternate delimiter instead of `/` like `~` or `#` – anubhava Dec 02 '22 at 16:10
  • Or [this](https://stackoverflow.com/questions/16790793/how-to-insert-strings-containing-slashes-with-sed) ? Spells your problem out in the title, closed as a dupe of the above. – tink Dec 02 '22 at 17:12

2 Answers2

0

Thanks, the following worked for me!

sed -i -e "s/;date\.timezone =/date.timezone = Europe\/Berlin/" text.txt
leonms.dev
  • 33
  • 1
  • 8
0

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
Gonzalo Matheu
  • 8,984
  • 5
  • 35
  • 58