Last active
March 29, 2021 00:41
-
-
Save RohithKumar1368/bf4f1b0b17cea6875aa642bc119aa554 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
set logfile=log.txt | |
:main | |
echo 1.insert | |
echo 2.delete | |
echo 3.update | |
set /p opt=select an option: | |
if %opt%==1 GOTO insert | |
if %opt%==2 GOTO delete | |
if %opt%==3 GOTO update | |
if %opt% gtr 3 ( | |
if %opt% lss 1 ( | |
echo Invalid Option. Please select again | |
GOTO main | |
) | |
) | |
:select | |
set /p choice=select Y to continue or N to exit: | |
if %choice%==Y GOTO main | |
if %choice%==N EXIT /B | |
:insert | |
setlocal EnableDelayedExpansion | |
set /p formid=Enter a formid: | |
set formid=%formid:a=A% | |
set formid=%formid:b=B% | |
set formid=%formid:c=C% | |
set formid=%formid:d=D% | |
set formid=%formid:e=E% | |
set formid=%formid:f=F% | |
set formid=%formid:g=G% | |
set formid=%formid:h=H% | |
set formid=%formid:i=I% | |
set formid=%formid:j=J% | |
set formid=%formid:k=K% | |
set formid=%formid:l=L% | |
set formid=%formid:m=M% | |
set formid=%formid:n=N% | |
set formid=%formid:o=O% | |
set formid=%formid:p=P% | |
set formid=%formid:q=Q% | |
set formid=%formid:r=R% | |
set formid=%formid:s=S% | |
set formid=%formid:t=T% | |
set formid=%formid:u=U% | |
set formid=%formid:v=V% | |
set formid=%formid:w=W% | |
set formid=%formid:x=X% | |
set formid=%formid:y=Y% | |
set formid=%formid:z=Z% | |
echo form id is %formid% | |
for /f "usebackq tokens=1 delims=," %%A in ("sample.csv") do ( | |
if "%%A" equ "%formid%" ( | |
echo %formid% already present in the file. Try updating the record. | |
GOTO main | |
) | |
) | |
:optionType | |
echo select a value for type of form: | |
echo 1.Endorsement | |
echo 2.Coverage | |
set /p val=select value: | |
if !val! equ 1 set type=Endorsement | |
if !val! equ 2 set type=Coverage | |
if !val! gtr 2 ( | |
echo invalid option, select either option 1 or option 2 | |
GOTO optionType | |
) | |
if !val! lss 1 ( | |
echo invalid option, select either option 1 or option 2 | |
GOTO optionType | |
) | |
:optionCategory | |
echo select a value for character of form: | |
echo 1.ISO | |
echo 2.Legal Name | |
set /p valCat=select value: | |
if !valCat! equ 1 set category=ISO | |
if !valCat! equ 2 set category=Legal Name | |
if !valCat! gtr 2 ( | |
echo invalid option, select either option 1 or option 2 | |
GOTO optionCategory | |
) | |
if !valCat! lss 1 ( | |
echo invalid option, select either option 1 or option 2 | |
GOTO optionCategory | |
) | |
echo %formid%,%type%,%category% | |
echo %formid%,%type%,%category%>>sample.csv | |
if %errorlevel% equ 0 ( | |
echo [%date%] [%time%] [Insert]: %formid%,%type%,%category% by %username% >>%logfile% | |
echo insert operation successful | |
) | |
if %errorlevel% gtr 0 echo insert operation failed | |
endlocal | |
GOTO select | |
:delete | |
setlocal EnableDelayedExpansion | |
set /p formid=Enter a formid: | |
if %errorlevel%==0 ( | |
findstr /V /b /L /C:"%formid%" sample.csv > ~demo.csv | |
echo string found and string removed | |
echo [%date%] [%time%] [Delete]: lines beginning with %formid% by %username% >>%logfile% | |
del sample.csv | |
copy ~demo.csv sample.csv 1>NUL | |
del ~demo.csv | |
) | |
if %errorlevel% GTR 0 echo string not found in the file | |
endlocal | |
GOTO select | |
:update | |
setlocal EnableDelayedExpansion | |
set /p formid=Enter a formid: | |
if not %errorlevel% equ 0 ( | |
echo %formid% not present in file. Try inserting it. | |
GOTO main | |
) | |
echo select category | |
echo 1.Change type | |
echo 2.Change category | |
set /p usr_choice=select category: | |
set InputFile=sample.csv | |
set OutputFile=~demo.csv | |
set _strFind=%formid% | |
Rem updating type options | |
if %usr_choice% equ 1 ( | |
:options | |
echo select the new value for type of form: | |
echo 1.Endorsement | |
echo 2.Coverage | |
set /p val=select type: | |
if !val! equ 1 set value=%formid%,Endorsement | |
if !val! equ 2 set value=%formid%,Coverage | |
if !val! gtr 2 ( | |
echo invalid option, select either option 1 or option 2 | |
GOTO options | |
) | |
if !val! lss 1 ( | |
echo invalid option, select either option 1 or option 2 | |
GOTO options | |
) | |
>"%OutputFile%" ( | |
for /f "usebackq tokens=1,2,3 delims=," %%A in ("%InputFile%") do ( | |
if "%%A" equ "%_strFind%" ( | |
echo !value!,%%C | |
echo [%date%] [%time%] [update]: from %_strFind%,%%B,%%C to !value!,%%C by %username% >>%logfile% | |
) | |
if not "%%A" equ "%_strFind%" (echo %%A,%%B,%%C) | |
) | |
) | |
del %InputFile% | |
copy %OutputFile% %InputFile% 1>NUL | |
del %OutputFile% | |
for /f "usebackq tokens=1,2,3 delims=," %%A in ("%InputFile%") do ( | |
if "%%A,%%B,%%C" equ "!value!,%%C" ( | |
echo Record updated successfully | |
) | |
) | |
) | |
if %usr_choice% equ 2 ( | |
echo select the new value for category: | |
echo 1.ISO | |
echo 2.Legal Name | |
set /p valCat=select category: | |
if !valCat! equ 1 set value=ISO | |
if !valCat! equ 2 set value=Legal Name | |
if !valCat! gtr 2 ( | |
echo invalid option, select either option 1 or option 2 | |
GOTO options | |
) | |
if !valCat! lss 1 ( | |
echo invalid option, select either option 1 or option 2 | |
GOTO options | |
) | |
>"%OutputFile%" ( | |
for /f "usebackq tokens=1,2,3 delims=," %%A in ("%InputFile%") do ( | |
if "%%A" equ "%_strFind%" ( | |
echo %%A,%%B,!value! | |
echo [%date%] [%time%] [update]: from %_strFind%,%%B,%%C to %%A,%%B,!value! by %username% >>%logfile% | |
) | |
if not "%%A" equ "%_strFind%" (echo %%A,%%B,%%C) | |
) | |
) | |
del %InputFile% | |
copy %OutputFile% %InputFile% 1>NUL | |
del %OutputFile% | |
for /f "usebackq tokens=1,2,3 delims=," %%A in ("%InputFile%") do ( | |
if "%%A,%%B,%%C" equ "%formid%,%%B,!value!" ( | |
echo Record updated successfully | |
) | |
) | |
) | |
endlocal | |
GOTO select |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment