: Author Gerard O'Rourke : Date 05/03/2019 : To export Dial-peer config into table format : Note cannot handle dial-peer config which contain : a single quote (two quotes are ok) or "&" cls @echo off REM Setting a Timestamp variable which can be used in a batch file FOR /f "tokens=1-4 delims=/ " %%A IN ('date /t') DO ( set nday=%%A set nmonth=%%B set nyear=%%C ) set SORTDATE=%nyear%%nmonth%%nday% FOR /f "tokens=1-2 delims=: " %%A IN ('time /t') DO ( set hour=%%A set min=%%B ) set SORTTIME=%hour%%min% set TIMESTAMP=%sortdate%-%sorttime% REM *************************************************** REM START OF MAIN SCRIPT REM *************************************************** set runningconfig=MyRouterConfigFile.txt echo . set /p runningconfig=Please Enter your Router Config File [%runningconfig%]? echo. set dialpeerlist=~%runningconfig%-dialpeerlist.txt set tempfile=~%runningconfig%-temp.txt set outputfile=dialpeer-table-export_%runningconfig%_%TIMESTAMP%.csv REM create file list of voice dial-peer type %runningconfig% | find "dial-peer voice" > %dialpeerlist% REM Print Header echo "Filename","dial-peer","description","translation-profile incoming","direct-inward-dial","incoming called-num","destination-pattern","service","preference","session protocol","session target","voice-class codec","voice-class h323","dtmf-relay","fax","vad" > %outputfile% REM For Loop for each Dial-peer and create a temp file for just that dial-peer FOR /F "delims=" %%i IN (%dialpeerlist%) DO ( sed -n -e "/%%i/,/!/ p" %runningconfig% >%tempfile% REM type %tempfile% echo | set /p=. call :exportdata ) echo. echo Finished! echo. echo Note - If any errors on console windows - capture them now, correct the input files and rerun echo. pause del %tempfile% del %dialpeerlist% exit :exportdata SET description=. SET translation-profile=. SET preference=. SET destination-pattern=. SET session-protocol=. SET session-target=. SET voice-class-codec=. SET voice-class-h323=. SET dtmf-relay=. SET fax=. SET vad=. SET direct-inward-dial=. SET incoming=. SET service=. FOR /F "tokens=* USEBACKQ" %%F IN (`type %tempfile% ^| find "dial-peer voice"`) DO (SET dial-peer=%%F) FOR /F "tokens=* USEBACKQ" %%F IN (`type %tempfile% ^| find "description"`) DO (SET description=%%F) FOR /F "tokens=* USEBACKQ" %%F IN (`type %tempfile% ^| find "translation-profile incoming"`) DO (SET translation-profile="%%F") FOR /F "tokens=* USEBACKQ" %%F IN (`type %tempfile% ^| find "preference"`) DO (SET preference=%%F) FOR /F "tokens=* USEBACKQ" %%F IN (`type %tempfile% ^| find "destination-pattern"`) DO (SET destination-pattern=%%F) FOR /F "tokens=* USEBACKQ" %%F IN (`type %tempfile% ^| find "session protocol"`) DO (SET session-protocol=%%F) FOR /F "tokens=* USEBACKQ" %%F IN (`type %tempfile% ^| find "session target"`) DO (SET session-target=%%F) FOR /F "tokens=* USEBACKQ" %%F IN (`type %tempfile% ^| find "voice-class codec"`) DO (SET voice-class-codec=%%F) FOR /F "tokens=* USEBACKQ" %%F IN (`type %tempfile% ^| find "voice-class h323"`) DO (SET voice-class-h323=%%F) FOR /F "tokens=* USEBACKQ" %%F IN (`type %tempfile% ^| find "dtmf-relay"`) DO (SET dtmf-relay=%%F) FOR /F "tokens=* USEBACKQ" %%F IN (`type %tempfile% ^| find "fax"`) DO (SET fax=%%F) FOR /F "tokens=* USEBACKQ" %%F IN (`type %tempfile% ^| find "vad"`) DO (SET vad=%%F) FOR /F "tokens=* USEBACKQ" %%F IN (`type %tempfile% ^| find "direct-inward-dial"`) DO (SET direct-inward-dial=%%F) FOR /F "tokens=* USEBACKQ" %%F IN (`type %tempfile% ^| find "incoming called-number"`) DO (SET incoming=%%F) FOR /F "tokens=* USEBACKQ" %%F IN (`type %tempfile% ^| find "service"`) DO (SET service=%%F) echo "%runningconfig%","%dial-peer%","%description%","%translation-profile%","%direct-inward-dial%","%incoming%","%destination-pattern%","%service%","%preference%","%session-protocol%","%session-target%","%voice-class-codec%","%voice-class-h323%","%dtmf-relay%","%fax%","%vad%" >> %outputfile% exit /b