1.

Solve : BATCH to format text in files .txt?

Answer»

Hello,
I searched but I didn't found.
I need a COMMAD or an program to transform 3 lines or more in 1 line like:

I have following text:          111111111
                                      222222222
                                      333333333
                                      444444444
                                      555555555

I want to MAKE it like:    1111111111      2222222222       3333333333
                                 4444444444      5555555555

I tried EDLIN but didn't worked.
Thank you.if you have gawk for windows(see my sig)
Code: [Select]C:\test>more file.txt
111111111
222222222
333333333
444444444
555555555
666666666
777777777

C:\test>gawk "ORS=(NR%3==0)?\"\n\":\" \"" file.txt
111111111 222222222 333333333
444444444 555555555 666666666
777777777
if you prefer a native solution, an example vbscript here you can use Quote from: gh0std0g74 on July 01, 2009, 12:06:04 AM

if you have gawk for windows(see my sig)

Sorry I forgot to say that I'm using W2K OS.
 Ty, but i can't use "gawk for windows". Quote from: SuperSteaua on July 01, 2009, 12:57:54 AM
Sorry I forgot to say that I'm using W2K OS.
 Ty, but i can't use "gawk for windows".
gawk works on W2K as well. Its a matter of whether you want to download it or not. Its only a one time effort if you want to download and use it. However, if not, i have also shown you example of vbscript in the link. you can try that.heh, "I Have windows, so I can't use Gawk for windows"

classic. Code: [Select]echo off
setlocal enabledelayedexpansion

for /f %%a in (a.txt) do (
if not !num! equ 3 (set line=!line! %%a) ELSE (
set num=0
echo !line!
set line=%%a
)
set /a num+=1
)
echo %line%

pause
C:\>type strcat.bat
Code: [Select]echo off
setLocal EnableDelayedExpansion
set /a c=0

for /f "tokens=1-3 delims=" %%a in (strcon.txt) do (
set /a c+=1
set str!c!=%%a

set Final=!str1! !str2! !str3!
if !c! EQU 3 echo !Final!
if !c! EQU 3 set /a c=0 && set str1= && set str2= &&  set str3=

)
echo %Final%
Output:

C:\>strcat.bat
111111111 222222222 333333333
444444444 555555555 666666666
777777777
C:\>
C:\>type strcon.txt
111111111
222222222
333333333
444444444
555555555
666666666
777777777

C:\> Quote from: billrich on July 01, 2009, 09:23:08 AM
C:\>type strcat.bat

Code: [Select]echo off
setLocal EnableDelayedExpansion
set /a c=0

for /f "tokens=1-3 delims=" %%a in (strcon.txt) do (
set /a c+=1

set str!c!=%%a


)

set Final-1=%str1% %str2% %str3%
set Final-2=%str4% %str5% %str6%

echo  %Final-1%

echo  %Final-2%
Output:

C:\>strcat.bat
 111111111 222222222 333333333
 444444444 555555555
C:\>

C:\>type strcon.txt
111111111
222222222
333333333
444444444
555555555

C:\>
your SCRIPT doesn't take care of more input lines.07/02/2009 :

More input lines now possible. See post # 6  Bill


Quote from: gh0std0g74 on July 01, 2009, 10:16:58 AM


your script doesn't take care of more input lines.

Devcom post#5  beat  me to the draw.  His code is complete and nearly perfect.  I'm still learning. 

Maybe the non Batch solutions should be on another Board?

We might be overloading the newbies?I have to say that I realy can't use other STUFF than batch, because I use it on a server of an CLIENT and I can't INSTALL on it softweare without permision. And offcourse I don't have permision.


Quote from: devcom on July 01, 2009, 08:45:52 AM
Code: [Select]echo off
setlocal enabledelayedexpansion

for /f %%a in (a.txt) do (
if not !num! equ 3 (set line=!line! %%a) ELSE (
set num=0
echo !line!
set line=%%a
)
set /a num+=1
)
echo %line%

pause

This one seems to do the trick. But I didn't succeed to put the result into a result file DEVCOM if u can refine it please.


As for the other program it didn't worked for me.

Thank you in advance for u'r help.

Code: [Select]echo off
setlocal enabledelayedexpansion

for /f %%a in (a.txt) do (
if not !num! equ 3 (set line=!line! %%a) ELSE (
set num=0
echo !line! >>log.txt
set line=%%a
)
set /a num+=1
)
echo %line% >>log.txt

pause Quote from: devcom on July 02, 2009, 06:25:37 AM
Code: [Select]echo off
setlocal enabledelayedexpansion

for /f %%a in (a.txt) do (
if not !num! equ 3 (set line=!line! %%a) ELSE (
set num=0
echo !line! >>log.txt
set line=%%a
)
set /a num+=1
)
echo %line% >>log.txt

pause

Thank you very much.
It's working fine.
Problem solved.


Discussion

No Comment Found