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 start anchor fixes READY at the beginning and the whitespace class requires the field separator.
grep 'READY[[:space:]]$' status.txtIncorrect. $ anchors the end, so this does not match normal following fields.
Incorrect. The end anchor requires READY and whitespace to finish the line, so a node name would not match.
grep '^[[:space:]]READY' status.txtIncorrect. It requires leading whitespace before READY, the opposite position.
Incorrect. This allows leading whitespace, which is not the required line-start condition.
grep 'READY' status.txtIncorrect. It matches READY anywhere and also matches NOTREADY or READYING.
Incorrect. An unrestricted substring match also finds READY inside 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ロケール
- Use temporary files and harmless commands for pattern experiments.
- Regular-expression details should be checked against the target GNU implementation.
Foundation review
Place the condition
An anchor and a delimiter condition prevent a longer status name from matching accidentally.
Check the result
Test a status file containing READY, NOTREADY, and READYING lines.