Help merge strings of every three lines to one line

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
bars143
Posts: 87
Joined: 01 Sep 2013 20:47

Help merge strings of every three lines to one line

#1 Post by bars143 » 30 Sep 2013 23:08

hi experts,

i had made a working bat script with a menu :

Code: Select all

@echo off

:top
cls
echo select number in a menu below:
echo.

:: this four lines with three-columns below is what i suggested to create automatically using batch script:

echo.1.STATUS     2.ADDPIC    3.ADDPICD
echo.4.ALBUMS     5.ALLINFO   6.APICS
echo.7.COMMENT    8.DELPOST   9.FONLINE
echo.10.STREAM   11.like     12.POST

echo.
set /p "m=chosen number: "
set "n=%m%"

if %m% equ %n% goto %n%_here

:1_here
start "" fbcmd.bat status
goto top



but due to laziness of typing and i want help to give me an automatic script to give output result below as describe above with a comment:

Code: Select all

echo.1.STATUS     2.ADDPIC    3.ADDPICD
echo.4.ALBUMS     5.ALLINFO   6.APICS
echo.7.COMMENT    8.DELPOST   9.FONLINE
echo.10.STREAM   11.like     12.POST


that are coming from my text file with a total lines of 67 lines(but i cut it to 12 lines as for testing purpose) below:

Code: Select all

STATUS        
ADDPIC   
ADDPICD   
ALBUMS   
ALLINFO   
APICS    
COMMENT   
DELPOST   
FONLINE   
STREAM
LIKE
POST   



anyway i had other plans to create as many menus as possible and waiting for helpful bat script for faster processing.
and i repeat i want helpful script that from this input:

Code: Select all

STATUS        
ADDPIC   
ADDPICD   
ALBUMS   
ALLINFO   
APICS    
COMMENT   
DELPOST   
FONLINE   
STREAM
LIKE
POST   


to this output:

Code: Select all

echo.1.STATUS     2.ADDPIC     3.ADDPICD
echo.4.ALBUMS     5.ALLINFO    6.APICS
echo.7.COMMENT   8.DELPOST  9.FONLINE
echo.10.STREAM   11.LIKE        12.POST


to be use as embed to batch script in menu like GUI.

if it had an answer then it is very easy and fast to create batch menu. thanks to helping hands.
thank again to a helping hands.

Bars

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Help merge strings of every three lines to one line

#2 Post by foxidrive » 30 Sep 2013 23:54

This isn't perfect, but we don't know the limitations of your list to put in a lot of effort in getting it perfect.

"input.txt" is the file with the list.

Code: Select all

@echo off
setlocal EnableDelayedExpansion
set count=0
findstr /n "." "input.txt" >file.tmp

<file.tmp (for /f "delims=" %%a in (file.tmp) do (
set "a="
set "b="
set "c="
set /p "a="
set /p "b="
set /p "c="
set "d=!a!          "
set "e=!b!          "
set "f=!c!          "
set line=!d:~0,12! !e:~0,12! !f:~0,12!
if defined a echo !line!
))
del file.tmp
pause



Code: Select all

1:STATUS     2:ADDPIC     3:ADDPICD
4:ALBUMS     5:ALLINFO    6:APICS
7:COMMENT    8:DELPOST    9:FONLINE
10:STREAM    11:LIKE      12:POST

bars143
Posts: 87
Joined: 01 Sep 2013 20:47

Re: Help merge strings of every three lines to one line

#3 Post by bars143 » 01 Oct 2013 00:21

foxidrive wrote:This isn't perfect, but we don't know the limitations of your list to put in a lot of effort in getting it perfect.

"input.txt" is the file with the list.

Code: Select all

@echo off
setlocal EnableDelayedExpansion
set count=0
findstr /n "." "input.txt" >file.tmp

<file.tmp (for /f "delims=" %%a in (file.tmp) do (
set "a="
set "b="
set "c="
set /p "a="
set /p "b="
set /p "c="
set "d=!a!          "
set "e=!b!          "
set "f=!c!          "
set line=!d:~0,12! !e:~0,12! !f:~0,12!
if defined a echo !line!
))
del file.tmp
pause



Code: Select all

1:STATUS     2:ADDPIC     3:ADDPICD
4:ALBUMS     5:ALLINFO    6:APICS
7:COMMENT    8:DELPOST    9:FONLINE
10:STREAM    11:LIKE      12:POST


i will try your example above and try for other similar text files with a lines that are more than 12 lines
but thanks to your reply and i will do some homework after waiting for an answer.

a cheers !!! for you Foxi and your :idea: has many set commands that seems simple that i cant imagine ( im thinking of string manipulation and of caret trick)--anyway you had it of what i got now !!! :)

Bars
==========================================================

update:

foxi it is working great !!! to my 67 lines text file ,but as what you said--that is not perfect: an non-straight column as shown below:

Code: Select all

1:ADDALBUM        2:ADDPERM        3:ADDPIC
4:ADDPICD          5:ALBUMS         6:ALLINFO
7:APICS      8:AUTH           9:COMMENT
10:DELPOST        11:DISPLAY      12:EVENTS
13:FEED1            14:FEED2        15:FEEDLINK
16:FEEDNOTE      17:FEVENTS       18:FGROUPS
19:FINBOX          20:FINFO         21:FLAST
22:FONLINE        23:FPICS          24:FQL
25:FRIENDS        26:FSTATUS      27:FSTREAM
28:FULLPOST      29:GO         30:HELP
31:HOME      32:INBOX       33:LIKE
34:LIMITS          35:LOADDISP   36:LOADINFO
37:LOADNOTE      38:MSG       39:MUTUAL
40:MYWALL          41:NOTICES     42:NOTIFY
43:NSEND            44:OPICS        45:PINBOX
46:POST      47:PPICS       48:PPOST
49:RECENT          50:RESET         51:RESTATUS
52:RSVP      53:SAVEDISP         54:SAVEINFO
55:SAVEPREF      56:SENTMAIL     57:SFILTERS
58:SHOWPERM      59:SHOWPREF     60:STATUS
61:STREAM          62:TAGPIC       63:UFIELDS
64:UPDATE          65:VERSION     66:WALLPOST
67:WHOAMI
Press any key to continue . . .


anyway thanks again for quick reply.

cheers again !!! :)

Bars

====================================================
update 2ndtime

hi foxi,

it is really perfect !!! as i remove all whitespace first in a input.txt before applying your code and it display a straight in each column -but a great but !!! --why this quote and code tags in our reply box does not display correctly when i paste there ???

========================================================

update 3rdtime

really my mistake of concluding without actually seeing the result as shown below:
(it is scattered in reply box but straight after posting !!!) :oops:
Last edited by bars143 on 01 Oct 2013 03:33, edited 1 time in total.

bars143
Posts: 87
Joined: 01 Sep 2013 20:47

Re: Help merge strings of every three lines to one line

#4 Post by bars143 » 01 Oct 2013 03:10

after a given answer from foxi ,then i made a batch script that create .bat's template but failed to stabilized last two lines which both has quotes to maintain actual text but failed to removed quotes when output-ted to a bat file.

here is my menu-embedder.bat:

Code: Select all

@echo off
setlocal EnableDelayedExpansion

echo.@echo off >> create-new-file.bat
echo.setlocal EnableDelayedExpansion >> create-new-file.bat
echo.echo.>> create-new-file.bat
echo.echo.list of menu: >> create-new-file.bat
echo.echo.>> create-new-file.bat

set /p "Input=source-filename: "
set count=0
findstr /n "." "%input%" >file.tmp

<file.tmp (for /f "delims=" %%a in (file.tmp) do (
set "a="
set "b="
set "c="
set /p "a="
set /p "b="
set /p "c="
set "d=!a!          "
set "e=!b!          "
set "f=!c!          "
set line=!d:~0,12! !e:~0,12! !f:~0,12!
if defined a echo echo.!line! >> create-new-file.bat
))

echo.echo. >> create-new-file.bat
echo.set /p "m=chosen number: " >> create-new-file.bat
echo.set "n=%%m%%" >> create-new-file.bat
echo.echo. >> create-new-file.bat
echo."if %%m%% gtr 12 echo you typed not in the menu&echo.press enter to go back&pause&goto top" >> create-new-file.bat
echo."if %%m%% equ %%n%% goto %%n%%_here" >> create-new-file.bat

del file.tmp
pause


here is the output of above code:

Code: Select all

@echo off 
setlocal EnableDelayedExpansion
echo.
echo.list of menu:
echo.
echo.1:ADDALBUM   2:ADDPERM    3:ADDPIC     
echo.4:ADDPICD    5:ALBUMS     6:ALLINFO   
echo.7:APICS      8:AUTH       9:COMMENT   
echo.10:DELPOST   11:DISPLAY   12:EVENTS   
echo.13:FEED1     14:FEED2     15:FEEDLINK 
echo.16:FEEDNOTE  17:FEVENTS   18:FGROUPS   
echo.19:FINBOX    20:FINFO     21:FLAST     
echo.22:FONLINE   23:FPICS     24:FQL       
echo.25:FRIENDS   26:FSTATUS   27:FSTREAM   
echo.28:FULLPOST  29:GO        30:HELP     
echo.31:HOME      32:INBOX     33:LIKE     
echo.34:LIMITS    35:LOADDISP  36:LOADINFO 
echo.37:LOADNOTE  38:MSG       39:MUTUAL   
echo.40:MYWALL    41:NOTICES   42:NOTIFY   
echo.43:NSEND     44:OPICS     45:PINBOX   
echo.46:POST      47:PPICS     48:PPOST     
echo.49:RECENT    50:RESET     51:RESTATUS 
echo.52:RSVP      53:SAVEDISP  54:SAVEINFO 
echo.55:SAVEPREF  56:SENTMAIL  57:SFILTERS 
echo.58:SHOWPERM  59:SHOWPREF  60:STATUS   
echo.61:STREAM    62:TAGPIC    63:UFIELDS   
echo.64:UPDATE    65:VERSION   66:WALLPOST 
echo.67:WHOAMI                         
echo.
set /p "m=chosen number: "
set "n=%m%"

echo.
"if %m% gtr 12 echo you typed not in the menu&echo.press enter to go back&pause&goto top"
"if %m% equ %n% goto %n%_here"



please anyone help to solve my problem?
i really want those last two lines should have no quotes -- so that it can run.
anyway i can remove it manually on output only.
i hope a working code will help remove quotes so no manuall removing of unwanted quotes.

thanks for help,
Bars


edited:for mistake:

i edited above and remove this:

Code: Select all

echo.set "p=%%target%%call" >> create-new-file.bat


and also rename from

Code: Select all

set "n="   


to

Code: Select all

 set "n=%m%"

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Help merge strings of every three lines to one line

#5 Post by foxidrive » 01 Oct 2013 08:06

The quotes aren't needed there. This should work if m and n are defined.

Code: Select all

if %m% gtr 12 echo you typed not in the menu&echo.press enter to go back&pause&goto :top
if %m% equ %n% goto :%n%_here

I think you actually want to echo the lines into another file - you need to escape & with ^&

Code: Select all

>>create-new-file.bat echo.if %%m%% gtr 12 echo you typed not in the menu^&echo.press enter to go back^&pause^&goto top
>>create-new-file.bat echo.if %%m%% equ %%n%% goto %%n%%_here

bars143
Posts: 87
Joined: 01 Sep 2013 20:47

Re: Help merge strings of every three lines to one line

#6 Post by bars143 » 01 Oct 2013 09:10

foxidrive wrote:The quotes aren't needed there. This should work if m and n are defined.

Code: Select all

if %m% gtr 12 echo you typed not in the menu&echo.press enter to go back&pause&goto :top
if %m% equ %n% goto :%n%_here

I think you actually want to echo the lines into another file - you need to escape & with ^&

Code: Select all

>>create-new-file.bat echo.if %%m%% gtr 12 echo you typed not in the menu^&echo.press enter to go back^&pause^&goto top
>>create-new-file.bat echo.if %%m%% equ %%n%% goto %%n%%_here


foxi thanks you very much !!!

solved those quotes and here is my initial batch i create to personalize fbcmd.bat( a text browser that use cmd.exe ),which is helpful for a gprs speed mobile phone as a modem to my netbook:

Code: Select all

@echo off 
setlocal EnableDelayedExpansion

:top
cls
set "1=ADDALBUM"
set "2=ADDPERM"
set "3=ADDPIC"
set "4=ADDPICD"
set "5=ALBUMS"
set "6=ALLINFO"
set "7=APICS"
set "8=AUTH"
set "9=COMMENT"
set "10=DELPOST"
set "11=DISPLAY"
set "12=EVENTS"
set "13=FEED1"
set "14=FEED2"
set "15=FEEDLINK"
set "16=FEEDNOTE"
set "17=FEVENTS"
set "18=FGROUPS"
set "19=FINBOX"
set "20=FINFO"
set "21=FLAST"
set "22=FONLINE"
set "23=FPICS"
set "24=FQL"
set "25=FRIENDS"
set "26=FSTATUS"
set "27=FSTREAM"
set "28=FULLPOST"
set "29=GO"
set "30=HELP"
set "31=HOME"
set "32=INBOX"
set "33=LIKE"
set "34=LIMITS"
set "35=LOADDISP"
set "36=LOADINFO"
set "37=LOADNOTE"
set "38=MSG"
set "39=MUTUAL"
set "40=MYWALL"
set "41=NOTICES"
set "42=NOTIFY"
set "43=NSEND"
set "44=OPICS"
set "45=PINBOX"
set "46=POST"
set "47=PPICS"
set "48=PPOST"
set "49=RECENT"
set "50=RESET"
set "51=RESTATUS"
set "52=RSVP"
set "53=SAVEDISP"
set "54=SAVEINFO"
set "55=SAVEPREF"
set "56=SENTMAIL"
set "57=SFILTERS"
set "58=SHOWPERM"
set "59=SHOWPREF"
set "60=STATUS"
set "61=STREAM"
set "62=TAGPIC"
set "63=UFIELDS"
set "64=UPDATE"
set "65=VERSION"
set "66=WALLPOST"
set "67=WHOAMI"

echo.
echo.list of menu:
echo.

echo.1:ADDALBUM   2:ADDPERM    3:ADDPIC     
echo.4:ADDPICD    5:ALBUMS     6:ALLINFO   
echo.7:APICS      8:AUTH       9:COMMENT   
echo.10:DELPOST   11:DISPLAY   12:EVENTS   
echo.13:FEED1     14:FEED2     15:FEEDLINK 
echo.16:FEEDNOTE  17:FEVENTS   18:FGROUPS   
echo.19:FINBOX    20:FINFO     21:FLAST     
echo.22:FONLINE   23:FPICS     24:FQL       
echo.25:FRIENDS   26:FSTATUS   27:FSTREAM   
echo.28:FULLPOST  29:GO        30:HELP     
echo.31:HOME      32:INBOX     33:LIKE     
echo.34:LIMITS    35:LOADDISP  36:LOADINFO 
echo.37:LOADNOTE  38:MSG       39:MUTUAL   
echo.40:MYWALL    41:NOTICES   42:NOTIFY   
echo.43:NSEND     44:OPICS     45:PINBOX   
echo.46:POST      47:PPICS     48:PPOST     
echo.49:RECENT    50:RESET     51:RESTATUS 
echo.52:RSVP      53:SAVEDISP  54:SAVEINFO 
echo.55:SAVEPREF  56:SENTMAIL  57:SFILTERS 
echo.58:SHOWPERM  59:SHOWPREF  60:STATUS   
echo.61:STREAM    62:TAGPIC    63:UFIELDS   
echo.64:UPDATE    65:VERSION   66:WALLPOST 
echo.67:WHOAMI                         
echo.
set /p "m=chosen number: "
set "n=%m%"
echo.
if %m% gtr 67 echo you typed not in the menu&echo.press enter to go back&pause&goto top
if %m% equ %n% goto :keep_here

:keep_here

echo.guides and examples:

echo.   ALLINFO =me
echo.   ALLINFO "Bob Smith"
echo.   status "is excited to play with fbcmd"
echo.   finfo birthday_date -csv
echo.   stream #family 25
echo.   COMMENT 3 "This was 3rd story in the last STREAM command I executed"
echo.   like 1,2,3,4,5
echo.   ADDPICD "c:\photos\jamaica" 1
echo.   ADDPICD "c:\photos\jamaica" 1234567890
echo.   POST "is sharing a link:" "CLI for Facebook" "http://fbcmd.dtompkins.com"
echo.   inbox 10
echo.   ppics =all
echo.

echo you choose !%m%! , then add parameter if needed:
echo.
set /p "param=set paramaters: "
echo.
echo.see this if parameters are quoted : !%m%! %param%
echo.
echo.then press anykey to run
pause>nul
start "" fbcmd.bat !%m%! %param%
goto top


a highly appreciation to foxi !!!
and to Aacini's help that inspire me to ask for more question. yet all answered thru this great forum!!!
cheers all !!! :)

Bars

Post Reply