-
[converter]srt를 txt로 바꿔주는 shell 프로그램Linux 2021. 1. 14. 18:28
shell 프로그램
srt -> txt
확장 프로그램을 이용해서 넷플릭스의 영어 자막을 다운로드 받았는데,
srt로 되어있어서 txt로 바꿔주는 프로그램을 만들었다.
직접 확장자를 바꿔주도 문제는 없는데, 일일이 바꾸기 귀찮아서 만든 것{chtxt.sh}
#!/bin/sh dir_array=`ls` for item in ${dir_array};do cd ${item} for file in *.srt;do mv "${file}" "${file%%srt}txt" done cd ../ done
프로그램 위치 : .(현재 디렉토리)
타겟 파일 위치 : */* (현재 디렉토리 안에 있는 모든 디렉토리의 srt 파일을 찾아 txt로 바꿔줌)
chtxt.sh ├── bigbang │ ├── bigbang\ theory\ season5-1.txt │ ├── bigbang\ theory\ season5-2.txt │ ├── bigbang\ theory\ season5-3.txt │ └── bigbang\ theory\ season5-4.txt ├── it_crowd │ ├── 1-1.txt │ ├── 1-2.txt │ ├── 1-3.txt │ └── 1-4.txt └── voyager ├── voyager1_1.txt ├── voyager1_2.txt └── voyager1_3.txt
*위 코드에서 srt나 txt를 다른 확장자로 바꿔 응용이 가능하다.
*docx 파일은 그냥 확장자를 txt로 바꾸면 문제가 생기기 때문에
파이썬으로 파일을 열어서, 읽어온 뒤에 같은 이름의 txt로 저장하는 코드를 짰다.
관련게시글
Python program - Convert docx to txt