Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Replace space caracter in a file by enter caracter

35 views
Skip to first unread message

zeke03

unread,
May 21, 2002, 11:27:41 AM5/21/02
to

Hello,

i have to threat a file (like this : aaaa * word * *

i want to replace space caracter by enter caracter, which would give:
aaaa
*
word
*
*


Have you an idea ? i try with sed, but it does not work....


Thanks

--
Use our news server 'news.foorum.com' from anywhere.
More details at: http://nnrpinfo.go.foorum.com/

Frank

unread,
May 21, 2002, 11:12:03 AM5/21/02
to
zeke03 <2002521-16...@foorum.com>...

^ i have to threat a file (like this : aaaa * word * *
^
^ i want to replace space caracter by enter caracter, which would give:
^ aaaa
^ *
^ word
^ *
^ *

Something like the following, which is from memory and untested:

::BEGIN SCRIPT::::::
Set FILE="Your file"
FOR /F "tokens=*" %%a in ('TYPE %File%') Do (
(FOR %%b in (%%a) Do Echo %%a)
)
::END SCRIPT::::::::

You might have to tinker with it some to get it working properly.

Frank

Frank

unread,
May 21, 2002, 3:17:11 PM5/21/02
to
Frank <01c200da$1f7de4d0$0125250a@oxxpwczznlwntxby>...

^ Something like the following, which is from memory and untested:

^ You might have to tinker with it some to get it working properly.

That script had a typo in it and I don't think it would have handled
asterisks the way you would like. If you want the asterisks expanded to
filenames (which I doubt) then use this:

::BEGIN SCRIPT::::::
Set FILE="Your file"
FOR /F "tokens=*" %%a in ('TYPE %File%') Do (

(FOR %%b in (%%a) Do Echo %%b)
)
::END SCRIPT::::::::

If you want the to remain as asterisks:

::BEGIN SCRIPT::::::
Set FILE="Your file"
FOR /F "tokens=*" %%a in ('TYPE %File%') Do (

Call :BreakAtSpace %%a
)
Goto :EOF
:BreakAtSpace
If NOT "%1"=="" Echo.%1&Shift&Goto :BreakAtSpace
Goto :EOF
::END SCRIPT

Frank

Herbert Kleebauer

unread,
May 21, 2002, 2:51:33 PM5/21/02
to
zeke03 wrote:
>
> Hello,
>
> i have to threat a file (like this : aaaa * word * *
>
> i want to replace space caracter by enter caracter, which would give:
> aaaa
> *
> word
> *
> *
>
> Have you an idea ? i try with sed, but it does not work....

If there are no special characters (like <>|) in your input
file you can use:

@echo off
setlocal>outfile
for /f "tokens=*" %%i in (infile) do set x="%%i"&call :sub
goto :eof
:sub
for /f "tokens=1* delims= " %%j in (%x%) do echo %%j>>outfile&set x="%%k"
if not %x%=="" goto sub


But empty lines are removed and consecutive spaces are replaced by a single
<CR><LF>. If there are special characters or any space has to be
replaced by a <CR><LF>, you can use:

@echo off
echo Bj@jzh`0X-`/PPPPPPa(DE(DM(DO(Dh(Ls(Lu(LX(LeZRR]EEEUYRX2Dx=>sbs2.com
echo 0DxFP,0Xx.t0P,=XtGsB4o@$?PIyU WwX0GwUY Wv;ovBX2Gv0ExGIuht6>>sbs2.com
echo ?@}IKuNWpe~Fpe?FNHlF?wGMECIQqo{Ox{T?kPv@jeoSeIlRFD@{AyEKj@>>sbs2.com
echo iqe~1NeAyR?mHAG~BGRgB{~H?o~TsdgCYqe?HR~upkpBG?~slJBCyA?@xA>>sbs2.com
echo LZp{xq`Cs?H[C_vHDyB?Hos@QslFA@wQ~~x}viH}`LYNBGyA?@xAB?sUq`>>sbs2.com
echo LRy@PwtCYQEuFK@A~BxPtDss@fFqjVmzD@qBEOEenU?`eHHeBCMs?FExep>>sbs2.com
echo LHsPBGyA?@xAunjzA}EKNs@CA?wQpQpKLBHv?s`WJ`LRCYyIWMJaejCksl>>sbs2.com
echo H[GyFGhHBwHZjjHeoFasuFUJeHeB?OsQH[xeHCPvqFj@oq@eNc?~}Nu??O>>sbs2.com
echo ~oEwoAjBKs?Zp`LBzHQzyEFrAWAG{EFrAqAGYwHTECIQ{coKIsaCsf{Oe~>>sbs2.com
echo CK}Ayre~CNFA{rAyEKFACrA{EKGAjbA}eKGSjNMtQFtc{OAyDGFj?{FDGQ>>sbs2.com
echo KAjNVk_OCAx@e?f{o?CosI}1EGizhljJ~H1ZeG}JBA~rACBMDGjjDG@g0>>sbs2.com

sbs2.com 0 " " "$0d$0a" <infile >outfile

::----------------------------------------------------------------------
:: Usage: sbs2.com NUMBER "STRING1" "STRING2" <infile >outfile
::
:: infile and outfile must not be the same file!
::
:: Substitutes the NUMBER ocurrence of STRING1 in infile by
:: STRING2 and writes the result to outfile
::
:: You can include any character in STRING1/2 by using its
:: hex value (e.g. $0d for <CR> or $1a for EOF)
::
:: If NUMBER = 0 all STRING1 are substituted by STRING2
::
:: If an error is detected or nothing is substituted, erorrlevel=0
:: replace the original file only if errorlevel>=1 (=number of
:: substitutions).
::
:: Instead of the double quotes (") you can also use single quotes (')
:: with a different meaning for string2:
:: "string2" : normal substitution
:: 'string2" : before substitution the output file is rewinded
:: "string2' : after substitution the outputfile is closed

0 new messages