提示技巧 [英] tips'n'tricks in awk

查看:51
本文介绍了提示技巧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找awk的警告,技巧等. 例如:

I'm looking for caveats, tips'n'tricks etc. for awk. For example:

awk '$9=="404"{a[$7]++}END{for(i in a)print a[i],i}' access.log|less

此代码,将打印按页面路径汇总的错误.

this code, will print errors aggregated by page path.

有一个技巧,可以通过将WHINY_USERS设置为任何非零值来对数组进行排序,以便在打印之前自动在数组上使用isort函数:

There is a trick, to sort an array by setting WHINY_USERS to any, nonzero value, to automatically use isort function on array before printing:

WHINY_USERS=1 awk '$9=="404"{a[$7]++}END{for(i in a)print a[i],i}' access.log|less

此代码将返回相同的错误,但按键名(路径)排序.

This code will return same errors but sorted by the key name (path).

我正在寻找更多类似的技巧-您是否知道列出这些技巧的任何资源?你能分享你知道的最好的把戏吗? 我从来没有找到awk Wiki-只是一遍又一遍地重复着同样的老屁...

I'm looking for more tricks like this one - do you know any resource which has them listed? could you share best tricks you know? I've never found awk wiki - only same old tuts repeated over and over...

推荐答案

在版本4.0中,gawk有调试器.

In version 4.0 gawk got a debugger.

http://www.gnu.org/software/gawk/manual/html_node/Debugger.html

Starting dgawk is exactly like running awk. The file(s) containing
the program and any supporting code are given on the command line
as arguments to one or more -f options. (dgawk is not designed to
debug command-line programs, only programs contained in files.) In
our case, we call dgawk like this:

     $ dgawk -f getopt.awk -f join.awk -f uniq.awk inputfile

这篇关于提示技巧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆