Relocate line to a certain position on another line

-3

Situation

I was putting together a script in which I knew I should have 17 fields, but I still did not know which ones to call, which looks like this:

// ds_ind_exig_iss
// ds_ind_exig_icms
// ds_ind_exig_impressao_documento
// ds_ind_exig_utilizacao_documento
// ds_ind_exig_livro_movimento_combustivel
// ds_ind_exig_registro_veiculo
// ds_ind_exig_registro_inventario
// ds_ind_oper_escrituracao_contabil
// ds_ind_oper_iss
// ds_ind_oper_retencao_tributaria
// ds_ind_oper_icms
// ds_ind_oper_icms_st
// ds_ind_oper_antecipacao_tributaria
// ds_ind_oper_ipi
// ds_ind_oper_registro_inventario

$registro0030 = array();
$registro0030[] = 1;
$registro0030[] = 7;
$registro0030[] = $this->dados['form'][''];
$registro0030[] = $this->dados['form'][''];
$registro0030[] = $this->dados['form'][''];
$registro0030[] = $this->dados['form'][''];
$registro0030[] = $this->dados['form'][''];
$registro0030[] = $this->dados['form'][''];
$registro0030[] = $this->dados['form'][''];
$registro0030[] = $this->dados['form'][''];
$registro0030[] = $this->dados['form'][''];
$registro0030[] = $this->dados['form'][''];
$registro0030[] = $this->dados['form'][''];
$registro0030[] = $this->dados['form'][''];
$registro0030[] = $this->dados['form'][''];
$registro0030[] = $this->dados['form'][''];
$registro0030[] = $this->dados['form'][''];

Doubt

How do I reallocate the comment fields for each [''] , respectively, given that they follow a sequence?

    
asked by anonymous 05.01.2016 / 17:13

2 answers

0

The solution I developed was by REGEX

Adjustment

{1} ds_ind_exig_iss
{2} ds_ind_exig_icms
{3} ds_ind_exig_impressao_documento
{4} ds_ind_exig_utilizacao_documento
{5} ds_ind_exig_livro_movimento_combustivel
{6} ds_ind_exig_registro_veiculo
{7} ds_ind_exig_registro_inventario
{8} ds_ind_oper_escrituracao_contabil
{9} ds_ind_oper_iss
{10} ds_ind_oper_retencao_tributaria
{11} ds_ind_oper_icms
{12} ds_ind_oper_icms_st
{13} ds_ind_oper_antecipacao_tributaria
{14} ds_ind_oper_ipi
{15} ds_ind_oper_registro_inventario

$registro0030 = array();
$registro0030[] = 1;
$registro0030[] = 7;
$registro0030[] = $this->dados['form']['{1}'];
$registro0030[] = $this->dados['form']['{2}'];
$registro0030[] = $this->dados['form']['{3}'];
$registro0030[] = $this->dados['form']['{4}'];
$registro0030[] = $this->dados['form']['{5}'];
$registro0030[] = $this->dados['form']['{6}'];
$registro0030[] = $this->dados['form']['{7}'];
$registro0030[] = $this->dados['form']['{8}'];
$registro0030[] = $this->dados['form']['{9}'];
$registro0030[] = $this->dados['form']['{10}'];
$registro0030[] = $this->dados['form']['{11}'];
$registro0030[] = $this->dados['form']['{12}'];
$registro0030[] = $this->dados['form']['{13}'];
$registro0030[] = $this->dados['form']['{14}'];
$registro0030[] = $this->dados['form']['{15}'];

Regex

pattern : ^(\{\d+\}) (.*)\n([^%]+)(^.*)(.*\n)
replace : $3$4$2$5

Result

$registro0030 = array();
$registro0030[] = 1;
$registro0030[] = 7;
$registro0030[] = $this->dados['form']['ds_ind_exig_iss'];
$registro0030[] = $this->dados['form']['ds_ind_exig_icms'];
$registro0030[] = $this->dados['form']['ds_ind_exig_impressao_documento'];
$registro0030[] = $this->dados['form']['ds_ind_exig_utilizacao_documento'];
$registro0030[] = $this->dados['form']['ds_ind_exig_livro_movimento_combustivel'];
$registro0030[] = $this->dados['form']['ds_ind_exig_registro_veiculo'];
$registro0030[] = $this->dados['form']['ds_ind_exig_registro_inventario'];
$registro0030[] = $this->dados['form']['ds_ind_oper_escrituracao_contabil'];
$registro0030[] = $this->dados['form']['ds_ind_oper_iss'];
$registro0030[] = $this->dados['form']['ds_ind_oper_retencao_tributaria'];
$registro0030[] = $this->dados['form']['ds_ind_oper_icms'];
$registro0030[] = $this->dados['form']['ds_ind_oper_icms_st'];
$registro0030[] = $this->dados['form']['ds_ind_oper_antecipacao_tributaria'];
$registro0030[] = $this->dados['form']['ds_ind_oper_ipi'];
$registro0030[] = $this->dados['form']['ds_ind_oper_registro_inventario'];

Problems

As it is about REGEX and a specific search, it was necessary to execute 15 times the process. In my case as I used Sublime it was necessary to click 15 times on replace .

    
05.01.2016 / 17:18
1

Using vim (assuming vim is installed and has Perl support as usual)

:perldo if (m!// (.*)!){ push(@a,$1)};
:perldo s/''/"'".shift(@a)."'"/e
  • 1 holds in the vector @a values starting with% with%
  • 2 replaces each% with% of each saved value
05.01.2016 / 18:18