formatting command export sql with sed

0

I've exported a table from my database as follows:

"1";"Boi Preto";"2000-02-29";"2";"Sol Nascente";"2009-10-01";"3";"Parque Belo";"2007-03-15";"4";"Pedras Bonitas";"2017-12-12";"5";"Medeiros";"2011-06-22";

and needed to leave as follows:

01; Boi Preto; 2000-02-29
02; Sol Nascente; 2009-10-01
03; Parque Belo; 2007-03-15
04; Pedra Bonita; 2001-08-25
05; Nossa Senhora; 2011-06-22

How do I do this with thirst?

    
asked by anonymous 25.01.2018 / 13:59

1 answer

1

With awk , print three by three;

$ awk 'BEGIN{FS=OFS=";"} {for (i=1; i<NF; i+=3) print $i, $(i+1), $(i+2)}' arquivo
"1";"Boi Preto";"2000-02-29"
"2";"Sol Nascente";"2009-10-01"
"3";"Parque Belo";"2007-03-15"
"4";"Pedras Bonitas";"2017-12-12"
"5";"Medeiros";"2011-06-22"

If you want, you can save the code to a file:

$ cat mola.awk 
BEGIN{FS=OFS=";"}
{for (i=1; i<NF; i+=3) print $i, $(i+1), $(i+2)}

And do:

$ awk -f mola.awk arquivo
"1";"Boi Preto";"2000-02-29"
"2";"Sol Nascente";"2009-10-01"
"3";"Parque Belo";"2007-03-15"
"4";"Pedras Bonitas";"2017-12-12"
"5";"Medeiros";"2011-06-22"
    
25.01.2018 / 14:23