Created
September 10, 2024 02:05
-
-
Save markruler/03b08c78ca91b0dce916995f81698c74 to your computer and use it in GitHub Desktop.
text format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# 경로를 입력하지 않으면 에러 메시지를 출력하고 종료 | |
if [ -z "$1" ]; then | |
echo "Usage: $0 <directory_path>" | |
exit 1 | |
fi | |
# 파라미터로 받은 경로를 TARGET_DIR로 설정 | |
# 인코딩을 변경하고자 하는 디렉토리 경로를 설정합니다. | |
TARGET_DIR="$1" | |
# 디렉토리 하위 모든 파일을 순회하면서 인코딩을 변환합니다. | |
find "$TARGET_DIR" -type f | while read -r FILE; do | |
# 임시 파일 생성 | |
TEMP_FILE=$(mktemp) | |
# euc-kr에서 utf-8로 변환 (리디렉션으로 임시 파일에 출력) | |
iconv -f euc-kr -t utf-8 "$FILE" > "$TEMP_FILE" | |
# 변환이 성공적이라면 원본 파일을 덮어씁니다. | |
if [ $? -eq 0 ]; then | |
mv "$TEMP_FILE" "$FILE" | |
echo "Converted: $FILE" | |
else | |
echo "Failed to convert: $FILE" | |
rm "$TEMP_FILE" | |
fi | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# 경로를 입력하지 않으면 에러 메시지를 출력하고 종료 | |
if [ -z "$1" ]; then | |
echo "Usage: $0 <directory_path>" | |
exit 1 | |
fi | |
# 파라미터로 받은 경로를 TARGET_DIR로 설정 | |
# 줄바꿈 변환을 적용할 디렉토리 경로를 설정합니다. | |
TARGET_DIR="$1" | |
# 디렉토리 하위 모든 파일을 순회하면서 CRLF를 LF로 변환합니다. | |
find "$TARGET_DIR" -type f | while read -r FILE; do | |
# 임시 파일 생성 | |
TEMP_FILE=$(mktemp) | |
# CRLF -> LF 변환 | |
tr -d '\r' < "$FILE" > "$TEMP_FILE" | |
# 변환이 성공적이라면 원본 파일을 덮어씁니다. | |
if [ $? -eq 0 ]; then | |
mv "$TEMP_FILE" "$FILE" | |
echo "Line endings converted to LF: $FILE" | |
else | |
echo "Failed to convert line endings: $FILE" | |
rm "$TEMP_FILE" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment