课程: Learning Linux Command Line

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Solution: Extract information from a text file

Solution: Extract information from a text file - Linux教程

课程: Learning Linux Command Line

Solution: Extract information from a text file

(upbeat music) - [Instructor] Let's take a look at how I solved this challenge. The file that we were provided was an archive, so the first step that I took was to write tar -xvf log.tar.gz. And this created a file called auth.log. As I'm sure you found out, that file's hundreds of lines long. So I wanted to get a sense of what I was looking for. Next, I wrote less auth.log, just to take a look at all the text. And scrolling around, I started seeing invalid user login attempts. For example, this line shows invalid user oracle, another shows invalid user db1inst1, and so on. Scrolling down, I can see user zznode, user ftpuser, and so on. Each of these lines has the string input userauth_request, so I know I can look for that. And on these lines, the username occurs at a specific position. I can count from the left, 1, separator, 2, 3, 4, 5, 6, 7, 8, 9. On each of these lines that say…

内容