user1508893
user1508893

Reputation: 9793

sed - replacing text with colon

I have this command:

sed -i  "s/a:b/b:c/g" file.txt

(in English: replace "a:b" with "b:c" in file.txt)

This doesn't work because of the colons in the subsitution text. How should I re-write the command?

Upvotes: 11

Views: 24495

Answers (2)

Mirage
Mirage

Reputation: 31548

In case you want be safe , you can escape the : colon

sed -re "s/a\:b/b\:c/g" temp.txt

Upvotes: 9

A B
A B

Reputation: 4148

This worked for me:

-->cat 1
a:bLINE1
a:bLINE2

-->cat 1 | sed 's/a:b/b:c/g'
b:cLINE1
b:cLINE2

Upvotes: 5

Related Questions