Artificial intelligent assistant

Append second field of second line to first line from file how to generate the following file ( example in ) to the file as described in example out , each last word in state line ( example in ) , should be added to the last line of the previos line example in HDFS worker01.gtdns.com state STARTED HDFS worker02.gtdns.com state STOP HDFS worker03.gtdns.com state STARTED HDFS worker05.gtdns.com state STARTED HDFS worker06.gtdns.com state STARTED HDFS worker07.gtdns.com state STARTED HDFS worker08.gtdns.com state STARTED HDFS worker09.gtdns.com state STOP example out ( expected results ) HDFS worker01.gtdns.com STARTED HDFS worker02.gtdns.com STOP HDFS worker03.gtdns.com STARTED HDFS worker05.gtdns.com STARTED HDFS worker06.gtdns.com STARTED HDFS worker07.gtdns.com STARTED HDFS worker08.gtdns.com STARTED HDFS worker09.gtdns.com STOP

awk '$1 == "HDFS" { printf( "%s ", $0 ) }; $1=="state" { print $2 }' /path/to/input


The `awk` script is fairly self-explanatory: On lines where the first field is `HDFS`, append a space to the line and print it as-is with no trailing newline. On lines where the first field is `state`, print the second field _with_ the (implied) trailing newline.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 0150ab20a4df90b96b4f146253099b55