0

UNIX にいくつかのテキスト ファイルがあります。

[{"creation_time":"2013-04-18 12:03:33","id":255,"type_id":100,"workflow":167000440},
{"creation_time":"2013-04-18 12:03:33","id":255,"type_id":100,"workflow":167000441}
]

最後の記号 ] を見つけて に置き換える SED ツールを使用して正規表現を記述する必要があるため、最終的な結果は次のようになります。

[{"creation_time":"2013-04-18 12:03:33","id":255,"type_id":100,"workflow":167000440},
{"creation_time":"2013-04-18 12:03:33","id":255,"type_id":100,"workflow":167000441}
,

前もって感謝します。

うおだて。助けてくれてありがとう、私はそれをチェックしてうまくいきましたが、タグ ] が私の式と同じ行にある場合、いくつかの状況が発生する可能性があります.

[{"creation_time":"2013-04-18 12:03:33","id":255,"type_id":100,"workflow":167000440},
{"creation_time":"2013-04-18 12:03:33","id":255,"type_id":100,"workflow":167000441}]

コメントよりコピペ

この正規表現を書きましたが、うまくいきませんsed -i '$s/]$//'

4

5 に答える 5

0

A safer alternative, depending on your input, would be something like this:

sed '/^ *\[/,/\] *$/ { /] *$/ s//,/; }'

Explanation

Only replace the ] if it is following a previous [ and only if it is the last character on the line. Note this will not work if the angle brackets are on the same line.

于 2013-04-18T12:38:24.003 に答える
0
sed '$s/]$/,/'

s/]$/,/これにより、最後の行 ( $) のみで置換 ( ) が行われます。

于 2013-04-18T12:38:33.740 に答える
0

以下を使用する必要があります。

sed -re 's/]$/,/' textfile.txt
于 2013-04-18T12:39:19.083 に答える