Computing.Net > Forums > Disk Operating System > Replace PIPE | character

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Replace PIPE | character

Reply to Message Icon

Name: ionutd
Date: June 15, 2009 at 00:30:20 Pacific
OS: Windows Vista
Subcategory: General
Comment:

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.



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: June 15, 2009 at 01:46:53 Pacific
Reply:

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 enableDELAYedexpansion

for /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


0

Response Number 2
Name: ghostdog
Date: June 15, 2009 at 02:23:51 Pacific
Reply:

get sed from here.
then on command line

C:\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


0

Response Number 3
Name: ionutd
Date: June 15, 2009 at 02:29:48 Pacific
Reply:

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?


0

Response Number 4
Name: Mechanix2Go
Date: June 15, 2009 at 03:02:23 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Replace PIPE | character

replace characters in text www.computing.net/answers/dos/replace-characters-in-text/14904.html

replace characters in txt www.computing.net/answers/dos/replace-characters-in-txt/13669.html

Make current time computer name www.computing.net/answers/dos/make-current-time-computer-name/12469.html