Skip to main content
Added a l="" for robustness.
Source Link
user232326
user232326

Assuming there are always one state after the HDFS, This solve the issue:

awk '$1=="HDFS"{l=$0;next};$1=="state"{print(l,$2);l=""}' file

$1=="HDFS"{ … } For lines the field 1 is HDFS do .
l=$0;next Store line in var l (elle, line) move to next line.
$1=="state"{ … } for lines that field 1 is state do …
{print(l,$2)} print the line stored in var l (elle) and field 2.
{l=""} Avoid printing stale (old) values of l.

Assuming there are always one state after the HDFS, This solve the issue:

awk '$1=="HDFS"{l=$0;next};$1=="state"{print(l,$2)}' file

$1=="HDFS"{ … } For lines the field 1 is HDFS do .
l=$0;next Store line in var l (elle, line) move to next line.
$1=="state"{ … } for lines that field 1 is state do …
{print(l,$2)} print the line stored in var l (elle) and field 2.

Assuming there are always one state after the HDFS, This solve the issue:

awk '$1=="HDFS"{l=$0;next};$1=="state"{print(l,$2);l=""}' file

$1=="HDFS"{ … } For lines the field 1 is HDFS do .
l=$0;next Store line in var l (elle, line) move to next line.
$1=="state"{ … } for lines that field 1 is state do …
{print(l,$2)} print the line stored in var l (elle) and field 2.
{l=""} Avoid printing stale (old) values of l.

Simplified
Source Link
user232326
user232326

Assuming there are always one state after the HDFS, This solve the issue:

awk '$1=="HDFS"{l=$0;next};$1=="state"{print(l,$2)}' file

$1=="HDFS"{ … } For lines the field 1 is HDFS do .
l=$0;next Store line in var l (elle, line) move to next line.
$1=="state"{ … } for lines that field 1 is state do …
{print(l,$2)} print the line stored in var l (elle) and field 2.

Assuming there are always one state after the HDFS, This solve the issue:

awk '$1=="HDFS"{l=$0;next};$1=="state"{print(l,$2)}' file

Assuming there are always one state after the HDFS, This solve the issue:

awk '$1=="HDFS"{l=$0;next};$1=="state"{print(l,$2)}' file

$1=="HDFS"{ … } For lines the field 1 is HDFS do .
l=$0;next Store line in var l (elle, line) move to next line.
$1=="state"{ … } for lines that field 1 is state do …
{print(l,$2)} print the line stored in var l (elle) and field 2.

Simplified
Source Link
user232326
user232326

Assuming there are always one state after the HDFS, This solve the issue:

awk '{if($1=="HDFS")'$1=="HDFS"{l=$0;next};if($1=="state");$1=="state"{print(l,$2)}}' file

Assuming there are always one state after the HDFS, This solve the issue:

awk '{if($1=="HDFS"){l=$0;next};if($1=="state"){print(l,$2)}}' file

Assuming there are always one state after the HDFS, This solve the issue:

awk '$1=="HDFS"{l=$0;next};$1=="state"{print(l,$2)}' file
Source Link
user232326
user232326
Loading