ヘッダーレコードの後に詳細行が続くファイルがあります。awkを使用して、ヘッダーの単語をファイル内の後続の行にタグ付けしたいと思います。各ヘッダーレコードには、特定の単語「header」が含まれています。
私のサンプルファイルは
h1_val header
this is line 1 under header set1
this is line 2 under header set1
this is line 3 under header set1
this is line 4 under header set1
h2_val header
this is line 1 under header set2
this is line 2 under header set2
this is line 3 under header set2
this is line 4 under header set2
私の出力は次のようになります
h1_val this is line 1 under header set1
h1_val this is line 2 under header set1
h1_val this is line 3 under header set1
h1_val this is line 4 under header set1
h2_val this is line 1 under header set2
h2_val this is line 2 under header set2
h2_val this is line 3 under header set2
h2_val this is line 4 under header set2
助けてください
ありがとう!!!
ghotiに感謝します。行がプレーンであれば、正常に機能しているようです。入力がコンマで区切られ、二重引用符で囲まれているように見える場合...awkはどのようなバリエーションである必要がありますか
"h1_val","header word"
"this is line 1","under header","set1"
"this is line 2","under header","set1"
"this is line 2","under header","set1"
"this is line 2","under header","set1"
"h2_val","header word"
"this is line 1","under header","set2"
"this is line 2","under header","set2"
"this is line 2","under header","set2"
"this is line 2","under header","set2"
ありがとう!!