WindowsからUnixへのデータの中立化

WindowsからUnixへのデータの中立化

他のプラットフォームファイル(Windows)で次のような多くのエラーが発生することがわかりました。ここ、私の正規表現で。ほとんどの場合、行は^M

dos2unixを実行する方法には、次のようないくつかの方法があるようです。ここ説明する。しかし、これが文字の^M問題、つまりすべてのWindowsシステムでUnixまで解決するのに十分かどうかはわかりません。

サンプルコード

while (my $file = readdir($DIR)) {
    ## Reset the counter
    my $c=0;
    ## Skip any files that aren't .tex
    next unless $file =~ /\.tex$/;

    ## Open the file
    open(my $fh,"$path/$dir/$file");
    ######### TODO  I think the replacement should be done here
    ######### Pseudocode : 's/\r\n/\n/' input.txt

    while (<$fh>) {...}

        s/\r\n\z//;  # TODO bug here, 
                     # This line is not affecting the file globally. 
                     # I need to somehow apply the replament to the file. 
                     # Probably, I should do it globally, since this seems to be only locally. 
                     # What do you think?

私のUNIXシステムでは、このようなデータを返します。

\subsection{3}^MA 45歳の男性は、過去1年間に数日前に食べた食べ物から粒子を吐き出したと言いました。

次の代替の違いは何ですか?

#1

s/\r\n\z//;

明らかな代替品はまったく返却されません。

#2

s/\r\n\z//g;

正しいデータを返しません。上記のデータ{3}^マ4それでも出力で見ることができます。

#サム

s/\R//g;

無効な方向のデータを返します。

\subsection{4}All the following are associated with an increased risk for gallstones, except:
\begin{question}{Why hemolysis can give gall stones?}Bilirubin accumulation.\end{question}
...
\begin{question}{Vomiting. Why?}Neuropathy of stomach. Changes in the nervous system of the intestinal system. Not using insulin all the time. % Ketone irritation possible. % ketoacidosis \end{question}

コメントまで、すべてが1行にあるので、#2ではありません。

Perlスクリプトでwin2unixを実行する正しい方法は何ですか?

ベストアンサー1

Siyuan Renのコメントには良い答えがあります。特定の方法でコマンドを使用します。

tofrodos

おすすめ記事