English 中文(简体)
两个Bash/Applescript需要阅读和操纵文件夹中的文字档案
原标题:Two Bash/Applescript needed to read and manipulate text files within folder

我有几十份(txt)文件,其中载有长篇(一行)的言词清单,我想用SOS X狮文本转换成音频文件。 为此,我需要在同声标上加入控制发言时间。

Script 1

这里是我档案中的形式:

Word1
Word2
Word3

在此,我需要创建音频文件:

Word1
[[slnc 600]]

[[slnc 900]]
Word1

[[slnc 3000]]

Word2
[[slnc 600]]

[[slnc 900]]
Word2

[[slnc 3000]]

Word3
[[slnc 600]]

[[slnc 900]]
Word3

[[slnc 3000]]

...etc,

文本档案载于我的桌面上,有一.叫Words。 如果可能的话,如果能够把文字指向这个文件夹上,并且通过每个文件在内部进行上述改动,就会很有价值。

<>2>

这一点需要用一个称为法语的桌面文件,以表格形式对口语/手法进行阅读。 The tab-delimited .txt file Format:

FrenchWord/Phrase1   EnglishWord/Phrase1
FrenchWord/Phrase2   EnglishWord/Phrase2

...etc,

之后产出如下:

say "FrenchWord/Phrase1" using "Thomas"
delay 3
say "EnglishWord/Phrase1" using "Daniel"

delay 5

say "FrenchWord/Phrase2" using "Thomas"
delay 3
say "EnglishWord/Phrase2" using "Daniel"

delay 5

...etc,

由于该案中的txt投入文件既包含单一字句,我猜测,该笔文字需要把所有未定的标语作为法文,以及一切定语作为英文。

任何援助都将受到极大赞赏!

Cheers,

纽约总部

问题回答
$ cat words.txt 
Word1
Word2
Word3
$ ./script1 words.txt # will produce words-with-timings.txt
$ cat words-with-timings.txt 
Word1
[[slnc 600]]

[[slnc 900]]
Word1

[[slnc 3000]]

Word2
[[slnc 600]]

[[slnc 900]]
Word2

[[slnc 3000]]

Word3
[[slnc 600]]

[[slnc 900]]
Word3

[[slnc 3000]]

$ cat phrases.txt 
FrenchWord/Bon jour EnglishWord/Good day
FrenchWord/Bon mot  EnglishWord/Well met
$ ./script2 phrases.txt # will produce phrases-with-timings.txt
$ cat phrases-with-timings.txt 
say "FrenchWord/Bon jour" using Thomas
delay 3
say "EnglishWord/Good day" using Daniel

delay 5

say "FrenchWord/Bon mot" using Thomas
delay 3
say "EnglishWord/Well met" using Daniel

delay 5

原文:

#!/bin/bash

for wordfile_txt in "$@"
do

  wordfile_with_timings_txt=`echo $wordfile_txt | sed s/.txt/-with-timings.txt/`

  # Refuse to overwrite
  if [[ "$wordfile_txt" == "$wordfile_with_timings_txt" ]]
  then
    echo ".txt files only pls"
    exit 1
  fi

  while read word
  do
    echo $word
    echo  [[slnc 600]] 
    echo
    echo  [[slnc 900]] 
    echo $word
    echo
    echo  [[slnc 3000]] 
    echo
  done < $wordfile_txt > $wordfile_with_timings_txt

done

文本:

#!/bin/bash

for phrasefile_txt in "$@"
do

  phrasefile_with_timings_txt=`echo $phrasefile_txt | sed s/.txt/-with-timings.txt/`

  # Refuse to overwrite
  if [[ "$phrasefile_txt" == "$phrasefile_with_timings_txt" ]]
  then
    echo ".txt files only pls"
    exit 1
  fi

  while read line
  do
    phrase1="`echo "$line" | cut -f 1`"
    phrase2="`echo "$line" | cut -f 2`"

    echo say "$phrase1" using "Thomas"
    echo delay 3
    echo say "$phrase2" using "Daniel"
    echo
    echo delay 5
    echo
  done < $phrasefile_txt > $phrasefile_with_timings_txt

done

在批次一中,建议使用<编码>find和xargs:

$ find lotta-words -type f
lotta-words/words1.txt
lotta-words/words2.txt
lotta-words/words3.txt
$ find lotta-words -type f | xargs ./script1 
$ find lotta-words -type f
lotta-words/words1-with-timings.txt
lotta-words/words1.txt
lotta-words/words2-with-timings.txt
lotta-words/words2.txt
lotta-words/words3-with-timings.txt
lotta-words/words3.txt




相关问题
Parse players currently in lobby

I m attempting to write a bash script to parse out the following log file and give me a list of CURRENT players in the room (so ignoring players that left, but including players that may have rejoined)...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

Bash usage of vi or emacs

From a programming standpoint, when you set the bash shell to use vi or emacs via set -o vi or set -o emacs What is actually going on here? I ve been reading a book where it claims the bash shell ...

Dynamically building a command in bash

I am construcing a command in bash dynamically. This works fine: COMMAND="java myclass" ${COMMAND} Now I want to dynamically construct a command that redirectes the output: LOG=">> myfile.log ...

Perform OR on two hash outputs of sha1sum

I want perform sha1sum file1 and sha1sum file2 and perform bitwise OR operation with them using bash. Output should be printable i.e 53a23bc2e24d039 ... (160 bit) How can I do this? I know echo $(( ...

Set screen-title from shellscript

Is it possible to set the Screen Title using a shell script? I thought about something like sending the key commands ctrl+A shift-A Name enter I searched for about an hour on how to emulate ...

热门标签