350-201 · Question #130
Which bash command will print all lines from the "colors.txt" file containing the non case-sensitive pattern "Yellow"?
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.
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
How the community answered
(25 responses)- A88% (22)
- C8% (2)
- D4% (1)
Why each option
The grep command with the -i flag performs case-insensitive pattern matching within file contents, printing all matching lines.
The grep -i flag enables case-insensitive matching, so 'grep -i "yellow" colors.txt' will match and print lines containing 'yellow', 'Yellow', 'YELLOW', or any mixed-case variant from the file colors.txt. The -i flag is the standard POSIX grep option for case-insensitive content search.
The locate command searches the file system index for files matching a name pattern and does not search within file contents.
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.
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
Source: https://www.gnu.org/software/grep/manual/grep.html
Topics
Community Discussion
No community discussion yet for this question.