Earlier quoted context omitted.
Ehh. Until the 'job' gets extended and then your simple tool makes it exponentially more complex and you have to rewrite it with the more powerful tool.
This is fine. I often "prototype" my automations as shell scripts, to explore what I actually want the tool to handle. Once it gets longer than 20 or so lines, it's time to move to a better language, but I don't mind rewriting. This is a chance to add error handling, config, proper arguments, built-in help texts and whatever else.
Awk: The Power and Promise of a 40-Year-Old Language
111–120 of 122 posts
Re: Awk: The Power and Promise of a 40-Year-Old Language
#112Earlier quoted context omitted.
I'm curious what linux distros don't have either some version of perl or python. I like awk, mind, but this is not necessarily (IME) a good argument for it.
A nice thing about awk vs. Perl/Python: there's a small focused set of things to learn. Once you learn them you're done. This suggests an opening for a Perl/Python intro focused on the exact same tasks, admittedly. That seems more realistic for Perl -- unless there's someone who writes Python one-liners at the shell?
For example, to print the first field of a line work the default delimiter could be accomplished in perl by running:
perl -ane 'print $F[0], "\n"'
Where $F[0] is the equivalent of $1 in awk.Re: Awk: The Power and Promise of a 40-Year-Old Language
#113Earlier quoted context omitted.
CSV is a complicated format but that does not mean awk is incapable of dealing with it. https://www.gnu.org/software/gawk/manual/html_node/Splitting... https://github.com/e36freak/awk-libs/blob/master/csv.awk https://raw.githubusercontent.com/Nomarian/Awk-Batteries/mas...
> CSV is a complicated format Surprisingly and unnecessarily so: > ["DSV"] is to Unix what CSV (comma-separated value) format is under Microsoft Windows and elsewhere outside the Unix world. CSV (fields separated by commas, double quotes used to escape commas, no continuation lines) is rarely found under Unix. > In fact, the Microsoft version of CSV is a textbook example of how not to design a textual file format. It…
Re: Awk: The Power and Promise of a 40-Year-Old Language
#114"A good programmer uses the most powerful tool to do a job. A great programmer uses the least powerful tool that does the job." I believe this, and I always try to find the combination of simple and lightweight tools which does the job at hand correctly. Awk sometimes proves surprisingly powerful. Just look at the concision of this awk one liner doing a fairly complex job: zcat large.log.gz | awk '{print $0 | "gzip -…
I really love that quote "..A good programmer...", do you have a source?
Re: Awk: The Power and Promise of a 40-Year-Old Language
#115Earlier quoted context omitted.
A nice thing about awk vs. Perl/Python: there's a small focused set of things to learn. Once you learn them you're done. This suggests an opening for a Perl/Python intro focused on the exact same tasks, admittedly. That seems more realistic for Perl -- unless there's someone who writes Python one-liners at the shell?
I don't think true python "one liners" are a thing, but the awkward thing about awk is sits in this place where what you are doing is complicated enough you need awk, but simple enough you need a one liner? Those cases have been exceedingly few and far between for me enough that every time I want to reach for awk I have to go lookup how to do anything more complex than printing fields. That completely defeats the poi…
Re: Awk: The Power and Promise of a 40-Year-Old Language
#116i no longer use it but Perl was always the better solution when one thought AWK was the answer. Perl will do those things where AWK really shines and if the problem got bigger, Perl was easier to deal with.
Perl was built initially as a sed/awk killer but got distracted into trying to take over the world. The interpreter for a language with 100x the number of features will always be slower. Also there's a very clear boundary for when I should use awk by itself, as part of a pipeline, or switch to a better tool. I feel like Perl has the potential to suck me imperceptibly into a huge mess where I spend 80% of my time refa…
Re: Awk: The Power and Promise of a 40-Year-Old Language
#117I've used Python almost my entire career, but started with out the UNIX tools. I never found awk interesting, then took a peek at it recently and understood: this was the pre-perl! it had scripting-language hash tables!
PERL was originally advertised as a replacement for “awk and sed”
These are days when things like GC, hashmaps, file operations etc were hard things on Unix.
Re: Awk: The Power and Promise of a 40-Year-Old Language
#118Earlier quoted context omitted.
The POSIX specification includes awk, but not perl or python. The world of UNIX and UNIX-likes is larger than just Linux distributions. Depending on the utility you plan on building and the platforms you expect it to run on, it may be wiser to reach for awk than other PLs.
Modern BSDs, macOS, and Solaris certainly have Perl and Python. (iOS and Android don't, but they don't have awk either.) What other Unixes are you thinking of? AIX, HP/UX, IRIX, UnixWare, etc. should be considered retrocomputing at this point and not relevant to modern compatibility discussions. Linux distros based on busybox, as mentioned elsewhere in this thread, are a more compelling reason for considering awk tha…
It’s not hard to install, but it’s not guaranteed to already be installed on every system.
Re: Awk: The Power and Promise of a 40-Year-Old Language
#119Earlier quoted context omitted.
CSV is a complicated format but that does not mean awk is incapable of dealing with it. https://www.gnu.org/software/gawk/manual/html_node/Splitting... https://github.com/e36freak/awk-libs/blob/master/csv.awk https://raw.githubusercontent.com/Nomarian/Awk-Batteries/mas...
> CSV is a complicated format Surprisingly and unnecessarily so: > ["DSV"] is to Unix what CSV (comma-separated value) format is under Microsoft Windows and elsewhere outside the Unix world. CSV (fields separated by commas, double quotes used to escape commas, no continuation lines) is rarely found under Unix. > In fact, the Microsoft version of CSV is a textbook example of how not to design a textual file format. It…
I KNOW how CSV works, for the most part. And my brain still started tuning out/stopped building up the mental model.
Re: Awk: The Power and Promise of a 40-Year-Old Language
#120Earlier quoted context omitted.
CSV is a complicated format but that does not mean awk is incapable of dealing with it. https://www.gnu.org/software/gawk/manual/html_node/Splitting... https://github.com/e36freak/awk-libs/blob/master/csv.awk https://raw.githubusercontent.com/Nomarian/Awk-Batteries/mas...
> CSV is a complicated format Surprisingly and unnecessarily so: > ["DSV"] is to Unix what CSV (comma-separated value) format is under Microsoft Windows and elsewhere outside the Unix world. CSV (fields separated by commas, double quotes used to escape commas, no continuation lines) is rarely found under Unix. > In fact, the Microsoft version of CSV is a textbook example of how not to design a textual file format. It…
One extension of the "Unix version" would be to impose a requirement like that in JSON, where all non-printable and/or non-ASCII characters must be written as an escape sequence like "\uXXXX" escape.