예시 CSV:
AAA, BBB, CCC, DDD, EEE, FFF, GGG, HHH
이제 열 2(BBB)를 복사하여 열 3 앞에 추가할 필요가 없으므로 파일은 다음과 같습니다.
AAA, BBB, BBB, CCC, DDD, EEE, FFF, GGG, HHH
답변1
$ 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
답변2
awk '{print $1,$2,$2,$3,$4,$5,$6,$7,$8}' file.csv
예:
➤ 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