Cisco
350-201 · Question #130
350-201 Question #130: Real Exam Question with Answer & Explanation
The correct answer is A: grep -i "yellow" colors.txt. The grep command with the -i flag performs case-insensitive pattern matching within file contents, printing all matching lines.
Automation
Question
Which bash command will print all lines from the "colors.txt" file containing the non case-sensitive pattern "Yellow"?
Options
- Agrep -i "yellow" colors.txt
- Blocate "yellow" colors.txt
- Clocate -i "Yellow" colors.txt
- Dgrep "Yellow" colors.txt
Explanation
The grep command with the -i flag performs case-insensitive pattern matching within file contents, printing all matching lines.
Common mistakes.
- B. The locate command searches the file system index for files matching a name pattern and does not search within file contents.
- C. locate does not support a -i flag for content searching and does not read file contents - it only locates files by name in the system database.
- D. grep without -i performs a case-sensitive match, so 'grep "Yellow"' would only match lines with that exact capitalization and would miss 'yellow' or 'YELLOW'.
Concept tested. grep case-insensitive file content pattern matching
Reference. https://www.gnu.org/software/grep/manual/grep.html
Topics
#bash scripting#grep#pattern matching#command line
Community Discussion
No community discussion yet for this question.