sed - Exact pattern matching and replace

Hi Team,

I am facing a problem as under, Suppose I have a file (test.txt) with the below content (all braces and slashes are included in the contents of the file)

[/]
[/abc/rep]
[/ab/cd/ef]

Now I want to append few words below matched line, I have written the below sed:

sed '/option/a insert text here' test

So for pattern [/] I ran it like this:

sed '/[/]/a added' test.txt

But it adds the word "added" both below every line. how to avoid this problem.

[/]
added
[/abc/rep]
added
[/ab/cd/ef]
added

Seems its just looking for / in every line.

Thanks

sed '/\[\/\]/a added' filename
1 Like

try:

sed '/[[][/][]]/a added' infile
1 Like