LInux 排序/uniq apache 日志
我有小文件(100)行网络请求(apache std 格式),有来自客户端的多个请求。我只想在我的文件中包含来自唯一 IP 的请求(行)列表,并且是
迄今为止我拥有的 最新条目 /home/$: cat all.txt | awk '{ 打印 $1}' |排序 -u | “{打印整行??}”
上面给了我IP(大约30,这是正确的)现在我还需要该行的其余部分(请求)。
I have small file (100) lines of web request(apache std format) there are multiple request from clients. I want to ONLY have a list of request(lines) in my file that comes from a UNIQUE IP and is the latest entry
I have so far
/home/$: cat all.txt | awk '{ print $1}' | sort -u | "{print the whole line ??}"
The above gives me the IP's(bout 30 which is right) now i need to have the rest of the line(request) as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用关联数组来跟踪您已经找到的 IP:
这将打印每个 IP 的第一行。如果你想要最后一个,那么:
Use an associative array to keep track of which IPs you've found already:
This will print the first line for each IP. If you want the last one then:
我讨厌 unique 没有提供与 sort 相同的选项,或者 sort 不能做到它所说的,我认为这应该工作[1],
但可惜,它没有;
因此,我们似乎陷入了做一些愚蠢的事情,
Which确实效率低下,但是“有效”(尚未测试过:模块拼写错误) [1]
比如根据手册页,
I hate that unique doesn't come with the same options as sort, or that sort cannot do what it says, I reckon this should work[1],
but alas, it doesn't;
Therefore, it seems we're stuck at doing something silly like
Which is really inefficient, but 'works' (haven't tested it: module typo's then)
[1] according to the man-page
以下应该可行:
这以相反的顺序获取文件并使用第一个字段进行稳定排序,仅保留唯一的项目。
The following should work:
This takes the file in reverse order and does a stable sort using the first field, keeping only unique items.