単語の改行を維持しながら、真の引用符を丸い引用符に変更します。

単語の改行を維持しながら、真の引用符を丸い引用符に変更します。

単語の改行を省略せずに、真の引用符をスマートスマート引用符に変更する方法です。

この例には、一重引用符と二重引用符が含まれています。

入力する

1 I have bowed before only one sanyasi in my life, and that is 'Sri
2 Chandrasekharendra Saraswathi', known to the world as the "Parmacharya."
3 
4 Therefore, I was the ''modern 
5 Indian'',believer in science, and
6 with little concern for spiritual
7 diversions.

出力

1 I have bowed before only one sanyasi in my life, and that is ‘Sri
2 Chandrasekharendra Saraswathi’, known to the world as the “Parmacharya.”
3 
4 Therefore, I was the “modern 
5 Indian”,believer in science, and with
6 little concern for spiritual 
7 diversions.

ベストアンサー1

改行が問題にならないようにするには、段落全体またはファイル全体が単一の文字列として扱われるように置換を実行できます。 Perlを使用すると、-0777ファイル全体を一度に読み取ったり、-00段落モード(つまり、空白行で区切られたセクション、行番号が入力ファイルの一部ではない)を使用したりできます。

$ perl -0777 -pe 's/\x27\x27/"/g; s/\x27(.*?)\x27/‘$1’/gs; s/"(.*?)"/“$1”/gs; ' input
I have bowed before only one sanyasi in my life, and that is ‘Sri
Chandrasekharendra Saraswathi’, known to the world as the “Parmacharya.”

Therefore, I was the “modern 
Indian”, believer in science, and
with little concern for spiritual
diversions.

\x27私は引用をより簡単にするために単一引用符の16進表現を使用します。.*?すべての文字列を表しますが、できるだけ短い一致を示します。最初のルールは二重引用符を''二重引用符に変更します。

あるいは、GNU sedと同様に、-z入力をNULで区切られた文字列にインポートすると、通常のテキストファイルを一度に読み取ることができます。

$ sed -zEe 's/\x27\x27/"/g; s/\x27([^\x27]*)\x27/‘\1’/g; s/"([^"]*)"/“\1”/g; ' input
I have bowed before only one sanyasi in my life, and that is ‘Sri
Chandrasekharendra Saraswathi’, known to the world as the “Parmacharya.”

Therefore, I was the “modern 
Indian”, believer in science, and
with little concern for spiritual
diversions.

おすすめ記事