sed with literal string--not input file

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"

You have a single quotes conflict, so use:

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

If using bash, 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 ksh or any other ones :

echo string | sed ...

Tags:

Linux

Unix

Sed