2014-09-26 36 views
1

介紹。我有下面的代碼行:perl在文件上運行

perl -pe 's;(\//(.*?)\\glft);;g' 

其目的就是要把TEX源代碼註釋語言文字的美洲原住民語言,只提取英文翻譯。翻譯分散在整個文件中,但總是立即在\glft之前,並由//終止。因此,該代碼會刪除(包括)\\直至(幷包括)\glft的所有內容。

問題。我在我的macbook pro上運行終端上的perl。這對我一次可以運行代碼的字符數量施加了一個吝嗇的限制。我可以指示perl在整個文件上運行代碼嗎?我不介意它是否提取輸出並將其填入一個新文件,或將其放在輸入文件的末尾或其他明智的選項。

評論。此評論有用嗎?我確信這是一個低級別的問題,但我昨天才開始使用perl。一些示例代碼包含在下面。


他被硒\告訴〜也不伊格納西奧:``好了,給我200,現在,她將是你的 '' // \ endgl \ XE \ EX%\ {INDX hujuei。 @ {emph {huju \'ei},\ emph {huj \'uei} then'}}% \indx{[email protected]{\emph{wie}, \emph{wi\'e}, \emph{w\'ie} give'; \ emph {w \'iet \ ss {} e} give{\sc.pass}'}}% \indx{[email protected]{\emph{wi}, \emph{wisi}, \emph{w\'isi} two'}}%\ indx {tiwitati @ {\ emph {t \ k {\'i} wit \'ati} hundred'}}% \indx{[email protected]{\emph{witad}, \emph{w\'itad} alone'}}%\ indx { kzza'a @ {emph {kha'a},emph {kha'\'a},emph {kh \'a'a} father, se\~nor'}}% \indx{[email protected]{\emph{k\'ur} captive'}}%\ indx {u @ {emph {u} ,\ emph {'u},\ emph {'\'u},\ emph {'\ ku} {\ sc dim}}}%\ indx {tiutsze @ {\ emph {t \'i \ k ut \ ss {} e},\ emph {t \ ki \ k ut \ ss {} \'e} leave{\sc.pass}'}}% % \begingl Huj\'uei [then] % \zero- [\sc 3s-] + w\'ie- [give-] + t\ss{}e- [\sc pass-] + van [\sc pnct] % wi- [two-] + t\k iwit\'ati, [hundred] % w\'itad [alone] % Kha'a [Se\~nor] % Patr\'isu [Patricio] % 'a- [\sc :3s:3s-] + kur- [captive-] + 'u- [\sc dim-] + t\'i\k u- [leave-] + t\ss{}e- [\sc pass-] + va-- [\sc pnct--] + k. [\sc sub] \endilg \glft Then two hundred was given and the little slave was left to Se\~nor Patricio alone.// \endgl \xe {\medskip\footnotesize \noindent We have changed the translation from他被給了二百'給the two hundred was given', in light of the zero agreement on \emph{w\'iet\ss{}evan}'。在\ getref {n23}中,\ emph {benwi \'eik'a} give it to me now' agrees, via the prefix \emph{ben}, with the second singular agent, first singular recipient, and third singular object money':它不是無代理的\ emph {'in} {\ sc:1s:3s},無益\ emph {'a} {\ sc 2s:3s}或無主題\ emph {bei} {\ sc 2s:1s}。相比之下,\ emph {w \'iet \ ss {evan}與三分之一的單數論證一致:如果它同意收件人和對象,則前綴爲\ emph {'a} {\ sc:3s: 3s},如同一句的下一句。我們假設同意的論點是the two hundred', as the obvious alternatives seem less plausible given what we find elsewhere (that {\sc :3s:3s} \emph{'a} has been elided or that \emph{w\'ie} may optionally fail to agree with its patient and instead treat the recipient as a direct object). The explicit remention of Se\~nor Patricio in the next clause, and the concomitant indirect-cum-direct-object agreement \emph{'a}, might be taken in favour of viewing him as absent for the clause containing被給出'。 %\ medskip \%\ TH {}將\ emph {t \'i \ k ut \ ss {}}翻譯爲'be owned', but this makes it surprising that \emph{Kha'a Patr\'isu} agrees with the verb as a dative (a passivised agent would bear \emph{ba}',並且不會同意)並且\ emph {kur-'u} little captive' is incorporated (a passivised object would bear \emph{de} {\sc bas} and be free). Consequently, we prefer the gloss被保留'爲此,句法語法更加自然(\emph x was left to \emph y'); this also fits better with \getref{d6}. (We have not seen an active counterpart to this root, but TH records the overtly causitive/passive pair \emph{t\k{\'i}w-\k i} keep',\ emph {t \ k {\'i} w- \ ke} be kept' is attested.) \medskip} \ex<n25> % \indx{[email protected]{\emph{p'i} head'}}%\ indx {pza @ {\ emph {p'a} water'}}% \indx{[email protected]{\emph{hwe}, \emph{hw\'e} take'; emph {hw \'et \ ss {} e} take{\sc.pass}'}}% \indx{[email protected]{\emph{m\'isat\'u} church'}}%\ indx {kzzai @ {\ emph {kh \ ka \ ki}`name({\ sc v})'(另見\ em {kh \ ka})}}%%\ begingl \ zero- [\ sc 3s:3s-] + P'i- [head \ ct {12} - ] + p'a- [water \ ct {12 } - ] + hw \'e- [take-] + van [\ sc pnct]%m'isat \'u-- [church--] +'at,[\ sc loc]%P \'etra- - [Petra--] + m [\ sc sc]%\ zero- [\ sc 3s:3s-] + kh \ ka \ k i- [name-] + van。[\ sc pnct] \ endilg \ glft He帶她到教堂接受洗禮並給她佩特拉命名.//

回答

3

鑑於你的表達是正確的,運行此命令:

perl -p -i.orig -e 's;(\//(.*?)\\glft);;g' input.txt 

將原始輸入保存爲input.txt.originput.txt將包含固定的文件。

另一種方法是使用你的命令外殼重定向:

perl -pe 's;(\//(.*?)\\glft);;g' <input.txt> output.txt 

它會從input.txt輸入,並把處理結果爲output.txt

+0

謝謝,但是背叛了我的無知程度,'input.txt'這裏意味着一個名爲'input'的文件,擴展名爲'.txt',對不對?換句話說,我必須首先將我的(所有ascii)'.tex'文件保存爲'.txt'。 – 2014-09-26 10:21:12

+0

perl如何知道文件的位置? – 2014-09-26 10:21:51

+0

在我的示例中,它從當前工作目錄中的'input.txt'獲取輸入(如果您未更改它,可能是您的主目錄 - 在命令行中鍵入'pwd'以知道它。你也可以把它指向你的'.tex'文件,不需要重命名:'perl -pe'...'< file.tex > result.tex' – afenster 2014-09-26 10:24:49