0
I have 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 below:
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 it with sed?
I created a file called fmt.awk to make it easier did chmod +x fmt.awk and cat esportacao.txt | . /fmt.awk
– dark777
@dark777 O
awk -f fmt.awk esportacao.txt
:)– fedorqui
I did this but it returned the following error below: bash-4.4$ awk -f fmt.awk export.txt awk: fmt.awk:2: awk 'BEGIN{FS=OFS=";"} {for (i=1; i<NF; i+=3) print $i, $(i+1), $(i+2)}' | sed’s/"//g;s/$/;/g' awk: fmt.awk:2: invalid char ''' in Expression awk: fmt.awk:2: awk 'BEGIN{FS=OFS=";"} {for (i=1; i<NF; i+=3) print $i, $(i+1), $(i+2)}' | sed’s/"///g;s/$/;/g' awk: fmt.awk:2: syntax error removed sed it from the same error as sed would remove the quotes.
– dark777
@dark777 I put the code in a file. Look at my edition
– fedorqui
Now funfou mas não teria como usar o mesmo para remover as quotes?
– dark777
@dark777
awk -f mola.awk arquivo | sed 's/"//g;s/$/;/g'
funfou for me.– fedorqui
I did a search and managed to get it to remove the quotes: BEGIN{FS=OFS=";"} {gsub(""",""); for (i=1; i<NF; i+=3) print $i, $(i+1), $(i+2)}
– dark777