0
我々は、ファイルに格納されているテキストの一行があるとします。私はLinuxでパターン文字列と別のパターン文字列を後で抽出する簡単な方法はありますか?
// The details, such as whether to put { character in front or not do not matter.
// Any form of output which extracts only these 3 entries and groups them in a
// visually nice way will do the job.
{ID:13, TIMESTAMP:1476280500}
{ID:25, TIMESTAMP:1476280600}
{ID:30, TIMESTAMP:1476280700}
// I do not want the last entry, because it does not contain timestamp field.
これまでのところ最も近いコマンド:
// In the actual file this will be one line
{unrelated_text1,ID:13, unrelated_text2,TIMESTAMP:1476280500,unrelated_text3},
{other_unrelated_text1,other_unrelated_text2,ID:25,TIMESTAMP:1476280600},
{ID:30,more_unrelated_text1,TIMESTAMP:1476280700},
{ID:40,final_unrelated_text}
私が欲しいものは、この特定の入力抽出のため3エントリです見つかったのは
grep -Po {ID:[0-9]+(.+?)} input_file
出力を示します
{unrelated_text1,ID:13,unrelated_text2,TIMESTAMP:1476280500,unrelated_text3}
{other_unrelated_text1,other_unrelated_text2,ID:25,TIMESTAMP:1476280600}
{ID:30,more_unrelated_text1,TIMESTAMP:1476280700}
{ID:40,final_unrelated_text}
私が探しています次の改善が、各エントリからunrelated_text
を削除しても、最後のエントリを削除する方法です。
質問:Linuxでこれを行うための最短の方法は何ですか?マルチchar型のRSとRTと単語の境界のためのGNUのawkで