I have a file \"test.txt\" that contain the following
+foo+
+bar+
What I want to do is to replace them into:
\'foo\'
\'bar\
Use " instead. And add g flag to replace all.
sed "s/\+/\'/g" test.txt
You can also replace all instances of + with ' in the file by using tr:
tr '+' "'" < inputfile
+ is not a special character without -r switch in sed. You can run the substitute command without any escaping:
echo '+foo+' | sed "s/+/'/g"
# output: 'foo'
If you want to save changed file then use:
sed -i.bak "s/+/'/g" test.txt
This might work for yoyu (GNU sed):
sed 'y/+/'\''/' file