![파일에 어떤 특수 문자가 있는지 찾아 해당 문자를 0으로 바꾸는 방법](https://linux55.com/image/190492/%ED%8C%8C%EC%9D%BC%EC%97%90%20%EC%96%B4%EB%96%A4%20%ED%8A%B9%EC%88%98%20%EB%AC%B8%EC%9E%90%EA%B0%80%20%EC%9E%88%EB%8A%94%EC%A7%80%20%EC%B0%BE%EC%95%84%20%ED%95%B4%EB%8B%B9%20%EB%AC%B8%EC%9E%90%EB%A5%BC%200%EC%9C%BC%EB%A1%9C%20%EB%B0%94%EA%BE%B8%EB%8A%94%20%EB%B0%A9%EB%B2%95.png)
아래와 같은 형식의 파일이 있습니다..
this is file data under the file 123�45
this is second line 123¿
나는 이런 O/P를 원한다.
this is file data under the file 123045
this is second line 1230
소스는 UTF-8 전용이라는 것입니다... 모든 UTF-8 문자는
001122��33 줄 과 같이 0으로 바꿔야 합니다 . 0011220033 줄은
다음과 같이 바꿔야 합니다.
이것은 수동으로 수행하는 데 사용하는 형식입니다.
grep -P "[^\x00-\x7F]" filename
답변1
사용 sed
:
LC_ALL=C sed -E 's/[^[:alnum:][:blank:]]+/0/g' < infile
A-Z
, 및 a-z
를 제외한 모든 문자를 0으로 바꿉니다. 위의 문자 클래스에 유지하려는 다른 문자를 추가하세요.0-9
Tab
Space
UTF-8 인 경우 locate
이를 사용하여 바이트 대신 문자를 바꾸십시오.
LC_ALL='C.UTF-8' sed -E 's/[^[:alnum:][:blank:]]/0/g' < infile
답변2
사용 tr
:
tr -sc '[:alnum:][:blank:]\n' 0
답변3
명령 1:sed "s/[?*_><&%#@]/0/g" filename
output
this is file data under the file 123045
this is second line 1230
명령 2:sed "s/[^a-z 0-9]/0/Ig" filename
산출
this is file data under the file 123045
this is second line 1230