Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello; Please excuse me for opening a new topic, but I have an urgent problem: I try to use a batch file (take it from this site also) to replace some PIPE "|" characters from a *.txt file with another character, let's say comma ","; but nothing happens; if the character is other then PIPE, then the batch is ok. The batch file has the following syntax:
@echo off
if "%1"=="GoTo" goto %2
%comspec% /v:on /c %0 GoTo start
goto:eof
:start
type nul> %temp%.\$
for /F "tokens=*" %%S in (filename.ext) do (
set str=%%S
echo !str:|=,!>> %temp%.\$
)
copy/y %temp%.\$ filename.ext > nul
del %temp%.\$
Thanks.

That script is too much of a mess to try to fix; or even comment on, except to say that it's not DOS.
To change | to , try this.
===============================
@echo off > newfile & setLocal enableDELAYedexpansionfor /f "tokens=* delims= " %%a in (myfile) do (
set str=%%a
echo !str:^|=,! >> newfile
)
=====================================
If at first you don't succeed, you're about average.M2

get sed from here.
then on command lineC:\test>more file.txt one|two |there |four 1|2|3|4|5|7|8 C:\test>sed "s/|/,/g" file.txt one,two ,there ,four 1,2,3,4,5,7,8

Thank you very much; It works! The output of your script is another file, so I've combine the two script above, and now I have the solution.
PS. I don't know scripting, but why are you saying the first script is a mess? there is problem with creating a temp file and deleting it?

I'll mention just 2:
!str! is meaningless without enableDELAYedexpansion.
/y with COPY is superfluous, since the default is to overwrite.
================
OK, one more.What's the purpose of the dot in :
%temp%.\$
=====================================
If at first you don't succeed, you're about average.M2

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |