Regex Hunt

Linux lab Intermediate 5 tasks 20 points

A suspicious file, leak.txt, turned up in your home directory. It mixes notes, email addresses, phone numbers and IP addresses. Pull out the useful parts with regular expressions.

How it works: the terminal below is a real Linux machine running in your browser. Click it and type. Tasks tick themselves off as you complete them; questions are answered in the box under each task. Press Reset any time for a fresh machine. Your password on this machine (for sudo) is student.

student@vulntech:~ Starting…
Getting your Linux machine ready…
The first start downloads about 20 MB. After that your browser keeps it, and labs start in a moment.

Hints

Build the pattern step by step with grep -oE and look at what it matches.

Solution explanation

The fakes have no @ followed by a domain with a dot, so [a-z0-9._]+@[a-z0-9-]+\.[a-z.]+ matches only the three real addresses. For phones, \b marks a word boundary, so 234-5678 inside 1234-5678 doesn't count (' 555-[0-9]{4}' would also work here). Dots in IP addresses must be written \., and !$ finds the line ending in !.

Show solution
grep -c '^#' leak.txt
grep -E '[a-z0-9._]+@[a-z0-9-]+\.[a-z.]+' leak.txt
grep -oE '\b[0-9]{3}-[0-9]{4}\b' leak.txt > phones.txt
grep -oE '10\.[0-9]+\.[0-9]+\.[0-9]+' leak.txt
grep '!$' leak.txt
HOME LEARN COMMUNITY DASHBOARD