sed -i -e "/"project1/baz"/ s/foo/bar/" test.txt
For example, i need to change word "foo" to word "bar" only if line contains "project1/baz", but as "project1/baz" contains "/" it throws an error: sed: can't find label for jump to `az/' what if instead of "project1/baz" sed input contained variable?