Quero ler a data de combined.csv
e adicioná-la como uma nova última coluna a um arquivo three.txt
.
A sua pergunta não é muito clara (mesmo depois de várias edições) e o seu ficheiro batch é quebrado de muitas formas diferentes.
Por favor, tente o seguinte arquivo de lote (example.cmd):
@echo off
setlocal
if exist three.txt del three.txt
rem get the date "01/12/15"
for /f "skip=5 tokens=1-10 usebackq delims=," %%a in ('type combined.csv') do (
set _date=%%d
goto :next
)
:next
rem add the date to the end of every line and output to "three.txt"
for /f "tokens=* usebackq" %%a in ('type combined.csv') do (
echo %%a,%_date%>>three.txt
)
endlocal
Exemplo de saída:
F:\test>type combined.csv
,Safaricom,,,,Channel to subscriber transfer,,,,,,,,,
,,,,,,,,,,,Report code :,,C2STRANSFER02,
,Network name :,,Safaricom,,,,,,,Service:,,,ALL,
,Zone :,,Safaricom Zone,,,,,,,Category :,,,ALL,
,Domain :,,Dealer Domain,,,,,,,User name :,,,ALL,
,Dated :,,02/12/15 08:56:46,,,,,,,Date :,,,01/12/15,
,Sl. No.,Transaction ID,,Request source,User name,Sender mobile number,Receiver mobile number,Service class,Service,Sub-service,Requested amount,Credit amount,Bonus,Process fee
,Transfer,,,,,,,,,,,,,
,1,R151201.2053.140019,,EXTGW,GAZETI LIMITED,700945609,700648591,PREPAID,Customer Recharge,Airtime,130.00,130.00,0.00,0.00
,2,R151201.2243.140015,,EXTGW,GAZETI LIMITED,700945609,727783637,PREPAID,Customer Recharge,Airtime,50.00,50.00,0.00,0.00
F:\test>example.cmd
F:\test>type three.txt
,Safaricom,,,,Channel to subscriber transfer,,,,,,,,,,01/12/15
,,,,,,,,,,,Report code :,,C2STRANSFER02,,01/12/15
,Network name :,,Safaricom,,,,,,,Service:,,,ALL,,01/12/15
,Zone :,,Safaricom Zone,,,,,,,Category :,,,ALL,,01/12/15
,Domain :,,Dealer Domain,,,,,,,User name :,,,ALL,,01/12/15
,Dated :,,02/12/15 08:56:46,,,,,,,Date :,,,01/12/15,,01/12/15
,Sl. No.,Transaction ID,,Request source,User name,Sender mobile number,Receiver mobile number,Service class,Service,Sub-service,Requested amount,Credit amount,Bonus,Process fee,01/12/15
,Transfer,,,,,,,,,,,,,,01/12/15
,1,R151201.2053.140019,,EXTGW,GAZETI LIMITED,700945609,700648591,PREPAID,Customer Recharge,Airtime,130.00,130.00,0.00,0.00,01/12/15
,2,R151201.2243.140015,,EXTGW,GAZETI LIMITED,700945609,727783637,PREPAID,Customer Recharge,Airtime,50.00,50.00,0.00,0.00,01/12/15
Leitura Adicional
- Um índice A-Z da linha de comando do Windows CMD - Uma excelente referência para todas as coisas relacionadas à linha do Windows cmd.
- para / f - Comando Loop contra os resultados de outro comando.
- ir para - Direcione um programa em lotes para ir para uma linha rotulada.
- tipo - Exibe o conteúdo de um ou mais arquivos de texto.