Solved Parsing a text file line by line performing other operations

June 13, 2017 at 17:15:45
Specs: Windows 7, 4
I am sharing the part I am struggling with , can I please request you to look into it and help me with how i can do this without breaking the loop.

for /f "tokens=1,2,3 delims= " %%a in (C:\testfolder\file1.txt) Do (
echo %%a %%b %%c>>C:\testfolder\URL.txt
Set Emailadd=%%a
Set Workbookname=%%b
Set Url=%%c
echo Worbookname is: %Workbookname! Url is: !Url! Email is :!Emailadd!

Pause
echo.
Set URL=!Workbookname!/!Url!
echo.
Pause
Call tableau directory path
tabcmd export "!URL!" --csv -f "C:\testfolder\!Emailadd!\testdemofinal.csv"
echo.
if ERRORLEVEL 0 (echo *** Tableau Report created and stored in the folder C:\testfolder)
if ERRORLEVEL 1 (echo *** error returned by tabcmd export & goto :tabcmd export)
))
:Remove combined column from the exported file
goto :3Param
::REM If statement to help choose where should the script proceed to.
:1Param
for /f "tokens=1,2,3* delims=," %%1 in (C:\testfolder\!Emailadd!\testdemofinal.csv) do (
echo (%%1,%%2,%%4)>>C:\testfolder\!Emailadd!\newfile.csv
)
goto :Dynamic Headers
:2Param
for /f "tokens=1,2,3,4* delims=," %%1 in (C:\testfolder\!Emailadd!\testdemofinal.csv) do (
echo (%%1,%%2,%%3,%%5)>>C:\testfolder\!Emailadd!\newfile.csv
)
goto :Dynamic Headers
:3Param
for /f "tokens=1,2,3,4,5* delims=," %%1 in (C:\testfolder\!Emailadd!\testdemofinal.csv) do (
echo (%%1,%%2,%%3,%%4,%%6)>>C:\testfolder\!Emailadd!\newfile.csv
)
goto :Dynamic Headers
)
:Dynamic Headers
Set ls=Lead State
Set dt=DeviceType

for /f "tokens=*" %%f in (C:\testfolder\!Emailadd!\newfile.csv) do (
set "line=%%f"
set string="Parameter3_Calculation"
set "line=!line:Parameter1_Calculation=%dt%!"
type "C:\testfolder\!!Emailadd!\newfile.csv" | find "%string%" > nul
if Errorlevel 0 (
set "line=!line:Parameter2_Calculation=%dt%!"
) Else (
REM No line:Parameter3_Calculation
)
type "C:\testfolder\!Emailadd!\newfile.csv" | find "%string%" > nul
if Errorlevel 0 (
set "line=!line:Parameter3_Calculation=%ls%!"
) Else (
REM No line:Parameter3_Calculation
)
echo !line!
)>> C:\testfolder\!Emailadd!\newfiledynamic.csv


:Use this to remove the string character
for /f "tokens=* delims=" %%a in (C:\testfolder\!Emailadd!\newfiledynamic.csv) do (
set oldName=%%a
set newName=!oldName:~1!
echo !newName!>>C:\testfolder\!Emailadd!\newfilename.csv
)
REM Pause
:logout
:: logout from server
echo. & echo Logging out of Tableau Server...
call Tableau Directory path
cls
:: suppress the *** 401 "Authorization Required" warning
:: tabcmd logout > nul 2>&1
:: Tableau Server 6.0.2 no longer outputs the 401 warning
tabcmd logout
echo *** Script completed.
echo.
echo *** Now we do the email part
echo.
Cd C:\
C:
blat -to !Emailadd! -subject "!Workbookname!_%Date%" -attacht C:\testfolder\!Emailadd!\newfilename.csv -body "Please see attached report. To explore or download the latest data visit sitename
if ERRORLEVEL 0 (echo *** Email Successfully sent)
if ERRORLEVEL 1 (echo *** error returned by blat & goto :erroremail)

goto :END
:sqlerror
Cd C:\
C:
blat -to !Emailadd! -subject "!Workbookname!_%Date%_Error" -body "Error in sql query"

goto :END
:subdirectoryerror
Cd C:\
C:
blat -to !Emailadd! -subject "!Workbookname!_%Date%_Error" -body "Error in subdirectory"
goto :END
:tabcmd export
Cd C:\
C:
blat -to !Emailadd! -subject "!Workbookname!_%Date%_Error" -body "Error in tabcmd export part"
goto :END
:erroremail
Cd C:\
C:
blat -to !Emailadd! -subject "!Workbookname!_%Date%_Error" -body "Error with sending email. Email may not be correct or may not exist."

goto :END
:END


See More: Parsing a text file line by line performing other operations

Reply ↓  Report •

#1
June 13, 2017 at 17:16:31
I am not sure how I can read a line from the file and do the operations and when that is done goto 2nd line and do the operations and so on.

Reply ↓  Report •

#2
June 15, 2017 at 03:47:25
Might be worth explaining what operations you want the code to perform, I am not able to provide a batch solution as I have no idea hoe to code in batch, but perhaps I could provide a vba solution?

In either case you need to explain from START to FINISH what you want the code to accomplish


Reply ↓  Report •

#3
June 17, 2017 at 06:26:06
✔ Best Answer
Also knowing the format of the file you are drawing from is helpful. If you run it with out turing off echo where does it fail. That's the Nice thing about batch is it shows you line by line untill it fails.

::mike


Reply ↓  Report •
Related Solutions


Ask Question