From the course: Bash Patterns and Regular Expressions
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Solution: Create a regex to find IPv4 addresses - Bash Tutorial
From the course: Bash Patterns and Regular Expressions
Solution: Create a regex to find IPv4 addresses
(upbeat music) - [Instructor] In this challenge, we parsed the IPaddresses.csv file in the Chapter 07 directory using sed and printed lines on the screen that contain IP version 4 addresses. As an additional challenge, I wanted only IP version 4 addresses on the screen using the best tool for the job. First off, let's talk about the Regex itself before we discuss tools. We have two groups. One of them matches the first three octets and the other matches the last octet. Let's take one octet and break it down. This matches zero through 99. This pattern matches 100 through 199. This matches 200 through 249 and lastly, this matches 200 through 255. Now let's talk tools. You probably figured out that sed is really good at matching and replacing patterns but not so good at inverting them. This solution satisfies the original challenge and prints out lines with IP version 4 addresses in them. The next solution types the output of the last sed statement into sed again and the second sed…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.