Reallocate line to a certain position of another line

Asked

Viewed 27 times

-3

Situation

I was riding a script in which I knew there should be 17 fields, but I still didn’t know with these they would call, after I was defining them in the comments, in such a way that it stayed this way :

// 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 to reallocate comment fields for each [''] respectively, in view of the following sequence:?

2 answers

1

Using vim (assuming that the vim installed and supported for Perl, as usual)

:perldo if (m!// (.*)!){ push(@a,$1)};
:perldo s/''/"'".shift(@a)."'"/e
  • 1 guard in vector @a the values started by // ....
  • 2 replaces each ''port each of the stored values

0


The solution I developed was to 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([^%]+)(^.*)\1(.*\n)
replace : $3$4$2$5

Upshot

$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

How it comes to REGEX and a specific search, it was necessary to run 15 times the process.
In my case as I used Sublime it was necessary to click 15 times on replace.

Browser other questions tagged

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