Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- macos
- GitLab
- 로그인불가
- ansible
- hardening
- proxycfg
- Proxy
- freebsd
- bash
- Windows
- Kibana server is not ready yet
- x-pack
- ssh key 배포
- Elasticsearch
- G-suite
- centos 8
- 보안양파
- pfsense
- PlayBook
- ELASTIC
- miniconda
- application security
- docker
- xe guest utilities
- XCP-ng
- elastic stack
- 한글가이드
- Kibana
- endpoint security
Archives
- Today
- Total
선 밖에 선 자유인
csv 파일 한글 깨짐 해결 본문
가끔 UTF-8 포맷으로 저장된 csv 파일의 경우 엑셀이나 여러 프로그램에서 한글이 깨짐. 막 깨짐
간단한 파이썬 코드로 EUC-KR로 포맷 변경
- char-convert.sh
- char-convert.py
#!/usr/bin/python import codecs infile = codecs.open('test.csv', 'r', encoding='utf-8') outfile = codecs.open('test2.csv', 'w', encoding='euc_kr') for line in infile: line = line.replace(u'\xa0', ' ') # 가끔 \xa0 문자열로 인해 오류가 발생하므로 변환 outfile.write(line) infile.close() outfile.close()응용: 쉘 스크립트를 이용해 해당 디렉토리의 파일들 모두 변경
- char-convert.sh
#!/bin/bash LIST=`ls -A1 | grep ".csv"` for file in $LIST do python ./char-convert.py $file done
- char-convert.py
#!/usr/bin/python #-*- coding: utf-8 -*- import codecs import sys file = sys.argv[1] file2 = file.split('.csv')[0]+"-2.csv" infile = codecs.open(file, 'r', encoding='utf-8') outfile = codecs.open(file2, 'w', encoding='euc_kr') for line in infile: line = line.replace(u'\xa0', ' ') outfile.write(line) infile.close() outfile.close()
Comments