Re: Insert caret just before specified character

"Tim Chase [email protected] [sed-users]" <[email protected]>
Newsgroups gmane.editors.sed.user
Message-ID <[email protected]>
On 2015-05-01 22:39, Petr Lázňovský [email protected] [sed-users] wrote:
> > AG [U [Fri, 1 May 2015 12:46:39 -0700]:
>  >> PLLC[U [Fri, 1 May 2015 12:38:42 -0700]:
> 
>  >> > How do I add caret '^' before each comma ',' in text string?
>  >> > Trying this:
>  >> > 
>  >> > echo {"errors":{"subject_id":["mandatory","Contact not
>  >> > exist."]}} | sed.exe -e "s/,/^,/g"
>  >> [...]
> 
>  >> Try enclosing the entire string in double-quotes or
>  >> single-quotes, something like echo "("errors":...}}" | sed ...
> >  
> >  Actually, not needed. Your first form works as-is on my W2K8
> > server with GNU sed version 4.2.1.
> >  
> 
> I see, it work from cmdline but problem seems arise in FOR loop
> usage.

As an alternative, put the sed command(s) in a file and invoke that
to prevent cmd.exe from seeing the "^"

  c:\temp> copy con my_script.sed
  s/,/^,/g
  ^Z

  c:\temp> echo {"errors":{"subject_id":["mandatory","Contact not exist."]}} | sed -f my_script.sed

-tkc
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.