Extract lines whose beginning is READY followed by whitespace.
Exclude names such as NOTREADY and READYING.
Which command is appropriate?
^ anchors the match at the beginning of a line, and a whitespace character after READY prevents prefix false positives.
Detailed explanation
grep '^READY[[:space:]]' status.txtCorrect. The pattern requires READY at the start followed by whitespace.
Correct. The pattern requires READY at the start followed by whitespace.
grep 'READY[[:space:]]$' status.txtIncorrect. $ anchors the end, so this does not match normal following fields.
Incorrect. $ anchors the end, so this does not match normal following fields.
grep '^[[:space:]]READY' status.txtIncorrect. It requires leading whitespace before READY, the opposite position.
Incorrect. It requires leading whitespace before READY, the opposite position.
grep 'READY' status.txtIncorrect. It matches READY anywhere and also matches NOTREADY or READYING.
Incorrect. It matches READY anywhere and also matches NOTREADY or READYING.
Try it yourself
An example you can run in a temporary verification environment.
printf 'READY node1\nNOTREADY node2\nREADYING node3\n' | grep '^READY[[:space:]]'Expected result
READY node1Key points
- ^ anchors the line start
- A character class matches whitespace
- Anchors prevent prefix matches
Notes
- Environment: GNU grep 3.x / C.UTF-8ロケール
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.