Sed with Literal String--Not Input File

sed with literal string--not input file

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 ...

Using sed command replace in the input text file all occurrences of characters '&', ' ', ' ' with their HTML entities

From info sed:

3.3 The 's' Command
[...]
The 's' command (as in substitute) is probably the most important in
'sed' [...]. The syntax of the 's' command is 's/REGEXP/REPLACEMENT/FLAGS'.
[...]
The REPLACEMENT can contain [...] unescaped '&' characters which reference the
whole matched portion of the pattern space.

Escape & with \ to \&.

find | xargs sed to substitute string in file name instead of file content

Drop the xargs and -0's.

find . -type f  | sed 's/file//g'

This takes the output of find and sends it as input to sed.



Related Topics



Leave a reply



Submit