AWK: Inserir cópia da coluna no meio do csv

2

Exemplo csv:

AAA, BBB, CCC, DDD, EEE, FFF, GGG, HHH

Agora, eu não quero copiar uma coluna 2 (BBB) e adicioná-la na frente da coluna 3 para que o arquivo se pareça com:

AAA, BBB, BBB, CCC, DDD, EEE, FFF, GGG, HHH
    
por T-One 31.08.2018 / 11:08

2 respostas

7
$ cat test.txt
AAA, BBB, CCC, DDD, EEE, FFF, GGG, HHH
AAA, BBB, CCC, DDD, EEE, FFF, GGG, HHH
AAA, BBB, CCC, DDD, EEE, FFF, GGG, HHH

$ awk -F, '{$2=$2","$2}1' OFS=, test.txt
AAA, BBB, BBB, CCC, DDD, EEE, FFF, GGG, HHH
AAA, BBB, BBB, CCC, DDD, EEE, FFF, GGG, HHH
AAA, BBB, BBB, CCC, DDD, EEE, FFF, GGG, HHH
    
por 31.08.2018 / 11:11
3

awk '{print $1,$2,$2,$3,$4,$5,$6,$7,$8}' file.csv

Exemplo:

 ➤ echo "AAA, BBB, CCC, DDD, EEE, FFF, GGG, HHH" | awk '{print $1,$2,$2,$3,$4,$5,$6,$7,$8}'
 AAA, BBB, BBB, CCC, DDD, EEE, FFF, GGG, HHH
    
por 31.08.2018 / 11:10

Tags