Tools like grep, ack, and ag make it easy to search for lines in a file that contain certain text and patterns. They all come with the -o flag which tells them to only show the part that matches.
This is particularly powerful when used with regex and piped into other programs.