help with bat scripts

Asked

Viewed 49 times

-1

I have a script for separating csv files,

what the script does and open the file and model the columns,

would like to know what I can change in this script to create a last column and repeat in the lines the file name.

@echo off
chcp 1252 > nul
SetLocal EnableDelayedExpansion

:: Coloque aqui o caminho para os arquivos csv 
set "Pasta=300"

:: Aqui será criada uma pasta com os arquivos modificados:
if not exist %Pasta%_mod md %Pasta%_mod 

for %%a in ("%Pasta%\*.csv") do (
echo Orgao;Matricula_Inst;Matricula;UPAG;UF;Nome;CPF;Rubrica;Sequencia;PMT;Prazo;CodUG;Status;Contrato>>"%Pasta%_mod\%%~nxa"

for /f "skip=1 usebackq tokens=*" %%b in ("%%a") do (
set "Linha=%%b"
set "Orgao=!Linha:~0,5!"
set "Matricula_Inst=!Linha:~5,7!"
set "Matricula=!Linha:~12,8!"
set "UPAG=!Linha:~20,9!"
set "UF=!Linha:~29,2!"
set "Nome=!Linha:~31,45!"
set "CPF=!Linha:~76,11!"
set "Rubrica=!Linha:~87,5!"
set "Sequencia=!Linha:~92,1!"
set "PMT=!Linha:~93,11!"
set "Prazo=!Linha:~104,3!"
set "CodUG=!Linha:~107,6!"
set "Status=!Linha:~113,12!"
set "Contrato=!Linha:~125,20!"
echo !Orgao!;!Matricula_Inst!;!Matricula!;!UPAG!;!UF!;!Nome!;!CPF!;!Rubrica!;!Sequencia!;!PMT!;!Prazo!;!CodUG!;!Status!;!Contrato!>>"%Pasta%_mod\%%~nxa"
)
)
:: Orgao=5 (0,5)
:: Matricula_Inst=7 (5,7)
:: Matricula=20 (12,8)
:: UPAG=29 (20,9)
:: UF=31 (29,2)
:: Nome=76 (31,45)
:: CPF=87 (76,11)
:: Rubrica=92 (87,5)
:: Sequencia=93 (92,1)
:: PMT=104 (93,11)
:: Prazo=107 (104,3)
:: CodUG=113 (107,6)
:: Status=125 (113,12)
:: Contrato=145 (125,20)
````

1 answer

0

Change that line:

echo !Orgao!;!Matricula_Inst!;!Matricula!;!UPAG!;!UF!;!Nome!;!CPF!;!Rubrica!;!Sequencia!;!PMT!;!Prazo!;!CodUG!;!Status!;!Contrato!>>"%Pasta%_mod\%%~nxa"

To:

echo !Orgao!;!Matricula_Inst!;!Matricula!;!UPAG!;!UF!;!Nome!;!CPF!;!Rubrica!;!Sequencia!;!PMT!;!Prazo!;!CodUG!;!Status!;!Contrato!;%%~na>>"%Pasta%_mod\%%~nxa"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.