Awk and ChatGPT are best friends.
The Awk Programming Language
61–70 of 159 posts
Re: The Awk Programming Language
#62I wish awk had support for addressing a range of fields, like from $1 to $7. `cut` supports it, FWIW.
Re: The Awk Programming Language
#63Earlier 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.
1. You can write totally unreadable perl. It is probably the single worst language in this regard most programmers will run into. Be careful to make your code readable.
2. Keep your amount of perl small. 200-300 lines is a good bit of it.
So for quick bang it out scripts that want to parse text etc... perl is great. For writing a major application, not so much.
Re: The Awk Programming Language
#64> "foo","bar,baz"
Re: The Awk Programming Language
#65Earlier quoted context omitted.
What would you suggest as an alternative to printing ASCII bar graphs? I do that all the time. Takes 20 seconds and often makes distributions, modalities, and patterns over time obvious right away.
`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
Re: The Awk Programming Language
#66I 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"
$ 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/xsvRe: The Awk Programming Language
#67Find and AWK together, a match made in heaven. Thanks for the link.
Re: The Awk Programming Language
#68Earlier 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?
edit: this prompted me to write up a little note showing how: https://notes.billmill.org/visualization/graphs/gnuplot/A_ba...
Re: The Awk Programming Language
#69Earlier 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.
Re: The Awk Programming Language
#70I 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…
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.