sed with literal string--not input file sed with literal string--not input file unix unix

sed with literal string--not input file


You have a single quotes conflict, so use:

 echo "A,B,C" | sed "s/,/','/g"

If using , you can do too (<<< is a here-string):

sed "s/,/','/g" <<< "A,B,C"

but not

sed "s/,/','/g"  "A,B,C"

because sed expect file(s) as argument(s)

EDIT:

if you use or any other ones :

echo string | sed ...


Works like you want:

echo "A,B,C" | sed s/,/\',\'/g


My version using variables in a bash script:

Find any backslashes and replace with forward slashes:

input="This has a backslash \\"output=$(echo "$input" | sed 's,\\,/,g')echo "$output"