srt 파일에서 줄 바꿈 및 단락 구분 기호 제거

srt 파일에서 줄 바꿈 및 단락 구분 기호 제거

저는 이 스크립트를 사용하여 자막에서 타임스탬프를 제거합니다.

awk '/-->/{for(i=1;i<d;i++){print a[i]};delete a;d=0;next}{a[++d]=$0}
    END{for(i in a)print a[i]}' xxxxx.srt > xxx.txt

그런 다음 결과를 줄바꿈과 단락바꿈이 제거된 웹페이지에 붙여넣었습니다. 단락이 하나 뿐이며 구분 기호 대신 공백이 있습니다. 다녀온 곳: https://www.textfixer.com/tools/remove-line-breaks.php

이러한 모든 작업을 하나의 명령으로 결합하는 솔루션을 찾고 있었지만 이를 수행하는 방법을 찾을 수 없습니다. 나는 awk에 대한 대안이 있다는 것을 알고 있습니다. Mac 터미널에서 이 작업을 쉽게 수행할 수 있는 모든 것이 나에게 적합할 것입니다!

도와주세요?

다음은 형식을 지정하고 싶지만 작동하지 않는 자막의 예입니다. 일부 자막이 작동하는 것을 본 적이 있는데... 이상하네요.

자막 파일

예상 출력:

Welcome to our program! This month’s theme is “Are You Paying Attention?” Strained relationships, illnesses, careers, entertainment —we’ll learn how to stay focused on Jehovah despite these potential distractions. We’ll see how our ministry is more effective when we focus on reaching the hearts of people. And our new song was written especially for you young adults to help you keep your eyes on the prize of life.

그러나 이것이 내가 귀하의 스크립트에서 얻은 것입니다.

    Welcome to our program!
 
 2
 00:00:06,089 --> 00:00:08,624
 This month’s theme is
 
 3
 00:00:08,625 --> 00:00:11,126
 “Are You Paying Attention?”
 
 4
 00:00:11,127 --> 00:00:13,595
 Strained relationships,
 
 5
 00:00:13,596 --> 00:00:16,131
 illnesses,
 

답변1

awk"단락 모드"에서 사용:

awk -v RS= '{
    for (i=5;i<=NF;i++){
      printf "%s%s", (sep ? " " : ""), $i
      sep=1
    }
  }
  END{ print "" }
' file.srt > file.txt

이는 레코드 구분 기호를 빈 문자열로 설정하고 레코드는 빈 줄로 구분됩니다. 각 레코드의 처음 4개 필드는 건너뛰고(필드 1은 줄 번호, 필드 2-4는 표시 시간) 첫 번째 필드를 제외한 모든 필드는 접두사 공백 문자로 인쇄됩니다.

마지막으로 개행 문자가 인쇄됩니다.

입력 파일:

1
00:00:06,453 --> 00:00:10,579
When one chooses to walk
the Way of the Mandalore,

2
00:00:10,581 --> 00:00:14,095
you are both hunter and prey.

3
00:00:17,935 --> 00:00:20,076
There is one job.

4
00:00:20,078 --> 00:00:21,945
Underworld?

5
00:00:21,947 --> 00:00:26,118
How uncharacteristic of
one of your reputation.

산출:

When one chooses to walk the Way of the Mandalore, you are both hunter and prey. There is one job. Underworld? How uncharacteristic of one of your reputation.

관련 정보