My other problem is that I want to accomplish things, not learn a tool, and it generally takes me a bit longer than it should to decide to actually learn something and not just hack at it.
Is it still worth it to be "the awk guy" at work?
81–90 of 159 posts
My other problem is that I want to accomplish things, not learn a tool, and it generally takes me a bit longer than it should to decide to actually learn something and not just hack at it.
Is it still worth it to be "the awk guy" at work?
Earlier quoted context omitted.
This is exactly why I moved from AWK to Perl for these quick jobs a couple of years ago. If you stick to an AWK-like subset, Perl is also simple, fast and lightweight. If you want to grow your scripts (and you have a lot of discipline) Perl – in contrast to AWK – gives you enough noose to hang^W^W^W^Wthe tools you need.
Perl? Wow. Is that better than bash, python or even nodejs? Why write in Perl over these? Serious question, was propaghandized to hate Perl.
Earlier quoted context omitted.
Perl? Wow. Is that better than bash, python or even nodejs? Why write in Perl over these? Serious question, was propaghandized to hate Perl.
I write bash python and nodejs all day, and have no professional history with Perl. One day while avoiding working on something important, I spent half a day learning Perl in order to implement something related to a build tool that was being used in the important thing I was avoiding. I was blown away. It's a really delightful language. Its big downfall is that it makes it feel good to do something "clever." Perl is…
In fact, Perl remains remarkably robust if you stack clever tricks on top of each other.
Earlier quoted context omitted.
Yes
One simple thing I do with awk is to create a command processor: read one line at a time and do things on my data as a response. This is very useful because you can make your command as powerful as needed and call other unix tools as a result.
Earlier quoted context omitted.
Its a crying shame we never settled on a control character separated text format. There's a ascii control characters for record and field (unit) separators. A bit of user space support for that would have been great.
Some discussion of that here: https://news.ycombinator.com/item?id=31220841 To be really useful as a format it would just need for text editors to: -display something distinct for the field separator (some editors do this) -treat the record separator character like a carriage return (not aware of any editors that do this)
Which would be trivial too.
I was privileged to be one of the technical reviewers for this book. There's a fair bit of the original content (which is still great), but Kernighan's done a great job with some good restructuring and some significant updates, too. The early chapters are very hands-on, with something of a focus on "exploratory data processing", particularly with CSV files. Big data with AWK, you could say. Gawk and awk will soon hav…
I love using Awk, the only thing I miss is that it can't handle complex csv files. Does anyone know how to handle quoted CSV strings like > "foo","bar,baz"
If quoted string is the only thing you need to handle extra (i.e. no escaped quotes, newlines, etc) and if you have GNU awk: $ echo '"foo","bar,baz"' | awk -v FPAT='"[^"]*"|[^,]*' '{print $1}' "foo" $ echo '"foo","bar,baz"' | awk -v FPAT='"[^"]*"|[^,]*' '{print $2}' "bar,baz" For a more robust solution, see https://stackoverflow.com/q/45420535 or use other tools like https://github.com/BurntSushi/xsv
echo '"foo","bar,baz","boo"' | awk -F"\",\"" '{print $1}' "foo
echo '"foo","bar,baz","boo"' | awk -F"\",\"" '{print $2}' bar,baz
echo '"foo","bar,baz","boo"' | awk -F"\",\"" '{print $3}' boo"
Realizing that I have to strip the quotes that remain.
Edit. formatting.
EDit, again, from your link, the following is more terse and too my taste (still needs strips):
awk -v FPAT='("[^"]*")+'
Earlier quoted context omitted.
But both require depending on a third party library -- hardly something on a whim if ASCII bar charts do the job?
gnuplot is an alternative that is available on almost as many systems as awk, and can do the job as well edit: this prompted me to write up a little note showing how: https://notes.billmill.org/visualization/graphs/gnuplot/A_ba...
Awk has always been a language that I loved but I have struggled to use besides quick jobs for parsing text files. I understand it is meant to be use for exactly that, but the fact that is simple, fast and lightweight sometimes makes me want to do something more with it, but when I start trying to do something besides parsing text I find that it starts becoming awkward (pun intented?).
... {
print $0 | "command"
}
"command" is executed once, and the pipe is kept open until closed explicitly by close("command"), at which point the next invocation will execute it again. The command string itself acts as a key for the pipe file descriptor.And of course, no mention of awk is complete without the "uniq" implementation, which beats the coreutils uniq in every way possible (by supporting arbitrary expressions as keys and not requiring sorted input):
!a[$0]++Earlier quoted context omitted.
`sparklines`[1] is good for an overall low-res view. `termgraph`[2] is sometimes better for a higher-res, more capable view (but can be finicky about the data.) [1] https://github.com/deeplook/sparklines [2] https://github.com/mkaz/termgraph
But both require depending on a third party library -- hardly something on a whim if ASCII bar charts do the job?
[1] 27623 14272 22218 21267 19037 989 27116 32405 23261 27104 7793 9432 7776 28832 13521 10783 29261 32193 30367 20358 22611 2023 19607 9844 3516 6510 16533 8378 22986 17043 14628 13392 22799 23847 29212 23690 17779 17059 28211 26180 32061 22740 7911 12018 4508 9801 9578 15350 9554 15517 11112 405 22054 2743 26609 7843 713 10975 2830 1126
[2] http://rjp-hosted-files.s3.amazonaws.com/sparkline-demo.png