| Newsgroups |
gmane.editors.sed.user |
| Message-ID |
<[email protected]> |
The problem was: the 'delimiter' characters are removed from string in moment the string is echoed into FOR loop:
for /f %a in ('echo _string_ ^| command') do (something...)
original sed solution does not work because commas was removed in moment ECHO command was executed, so this
for /f %a in ('echo _string_ ^| sed -e "s/,/^,/g" ^| command') do (something...)
trying escape ALREADY REMOVED characters. I discovered if string was enclosed withing doublequotes, it preserve commas but 'command' refuse to eat such string. Finaly I enclose string within doublequotes, than delete first and last character by sed and send stripped character into 'command' which work OK.
for /f %a in ('echo "_string_"^| sed -e "s/^.\(.*\).$/\1/" ^| command') do (something...)
Important notice: After string and first pipe MUST NOT be a space, because in this case trailing space is removed instead of last doublequotes.
L.
> Which windows version do you use?
> Commandline syntax inside a console window or inside a batch file is
> different.
> To make things more difficult, commandline syntax to declare a for loop
> inside a console window is different to one declared in a batch file.
> Furthermore it would be interesting to know, if you use sed in the
> declaration line of the loop [ eg. for /n %%a in ('xxx |sed
> "DoSomething"') Do (DoSomething)] or if you use sed INSIDE the loop [eg.
> for /n %%a in ('xxx') Do (echo x|sed "DoSomething")]. Behaviour here is
> different too.
>
> Would you provide a code example of your desired for loop?
> And again, should it be executed via console window or inside a batch file?
>
> Am 01.05.2015 um 22:39 schrieb Petr Lázňovský [email protected] [sed-users]:
>>> 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 ...
>> >> -Amarendra
>>> [...]
>>> 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.
>> Complex issue just posted into alt.msdos.batch.nt if someone interested.
>> Thank you anyway, L.
>> ------------------------------------
>> Posted by: =?windows-1250?Q?Petr_L=E1z=F2ovsk=FD?= <[email protected]>
>> ------------------------------------
>
>
>
>