I have some output that looks like the following:
Gathering data for drive 1 ...
Drive name: id1,sd@n5000cca17096
Drive Model: HUH721010AL4204
Drive Speed: 7200 RPMs
Drive Temp: 41 C
Gathering data for drive 2 ...
Drive name: id1,sd@n5000cca24156
Drive Model: HUH721010AL4204
Drive Speed: 7200 RPMs
Drive Temp: 41 C
Gathering data for drive 3 ...
Drive name: id1,sd@n5000cca8749
Drive Model: HUH721010AL4204
failed to get drive stats
Gathering data for drive 4 ...
Drive name: id1,sd@n5000cca19183
Drive Model: HUH721010AL4204
Drive Speed: 7200 RPMs
Drive Temp: 41 C
Gathering data for drive 5 ...
Drive name: id1,sd@n5000cca4607
Drive Model: HUSMH8010BSS204
failed to get drive stats
Gathering data for drive 6 ...
Drive name: id1,sd@n5000cca10152
Drive Model: HUH721010AL4204
Drive Speed: 7200 RPMs
Drive Temp: 41 C
I would like to print the "Drive name" for any drive in which the drive stats cannot be returned (so matching on failed to get drive stats
).
I know how to get the previous line with:
awk '$0=="failed to get drive stats" && $2>1 {print f} {f=$0}'
But that doesn't help me.
Desired output:
Drive name: id1,sd@n5000cca8749
Drive name: id1,sd@n5000cca4607
Edit:
For some reason when the output is redirected it doesn't appear the same way as it does on the terminal. If I run:
command >out.txt 2>&1
The output file will look like:
failed to get drive stats
failed to get drive stats
Gathering data for drive 1 ...
Drive name: id1,sd@n5000cca17096
Drive Model: HUH721010AL4204
Drive Speed: 7200 RPMs
Drive Temp: 41 C
Gathering data for drive 2 ...
Drive name: id1,sd@n5000cca24156
Drive Model: HUH721010AL4204
Drive Speed: 7200 RPMs
Drive Temp: 41 C
....
Both awk answers provided work but I just have other issues I guess