正規表現パターンに一致する文字列内から特定の文字を削除する方法を探しています。行ごとに 1 つのレコードがあるはずのタブ区切りファイルに改行を含むテキストを保存し、すべての改行をスペースに置き換えようとしています。最後の列 (英数字キーを持つ短い列) では改行は発生しません。
IMHO を解決する方法は\n
、次のパターン内のすべてのインスタンスを置き換えることです。
[^\t]*\t[^\t]*
これまでの私のソリューションでは、次の 3 つの手順を使用します。
- 「良い」
\n
を、テキストの残りの部分にない特別な文字列 (例: 長い数字) に置き換えます。ファイル内の意図した列数よりも 1 つ少ない列を使用しますs/\([^\t]*\t{x}[^\t]*\)\n/\1#12398754987235649876234#/g
。x
- すべての(「悪い」)
\n
をスペースに置き換えます - 長い数字を新しい行に置き換えます
しかし、かなりの数ギガバイトのテキスト ファイルがあり、これを 1つの sed
ステップで行う方法を探しています。
入力例:
foo \t Each multiplex has screens allocated \n
to each studio. \t abc \n
bar \t The screens need filling. \t bcd \n
123 \t Studios have to create product to fill \n
their screen, and the amount of good product is limited. \t cde \n
出力:
foo \t Each multiplex has screens allocated to each studio. \t abc \n
bar \t The screens need filling. \t bcd \n
123 \t Studios have to create product to fill their screen, and the amount of good product is limited. \t cde \n