Now that we have extracted all the IP addresses, we need to put them in order to process them further.Īnd if you need to “put something in order” - if you need to sort something at the Linux command line - then the tool “sort” is the way to go. (and isn’t simplicity always king?) Put the lines in order with sort Site note: Although the data extraction with grep is way more powerful than extracting data fields with cut, I’ll stick with “cut” for the rest of this article. So we can simply call “cut” in the following way, to extract all the IP addresses from a log file called “demolog”:Īs you see - as soon as you can describe the data you are interested in as a regular expression, you can use “grep” to extract only the data of interest. And this first field is separated by a single space from the rest of the line.We are interested in the first field of every line.This works in our example here perfectly: This tool is a command you can use, if you want to extract fields from lines of text, if these fields are separated with a dedicated single character from each other. The first approach is to use the command-line tool “cut” for extracting the IP addresses. Where the first part of every line shows the IP address where the request came from.Īnd our goal is now, to take the whole log file and generate the top 10 IP addresses that sent the most requests to my web server.Īnd if we wanna have a top 10 list of the IP addresses, we first need to extract them from the log.įor this step I wanna show you two different approaches: Extract the IP addresses with cut IP-ADDRESS - REQUEST & REQUEST-INFORMATION
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |