Walt Mankowski via plug on 10 Sep 2020 09:01:45 -0700


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] Awk *language*: was Win Subsystem for Linux2 broken


On Thu, Sep 10, 2020 at 11:00:38AM -0400, Steve Litt via plug wrote:
> On Thu, 10 Sep 2020 10:04:49 -0400
> Walt Mankowski via plug <plug@lists.phillylinux.org> wrote:
> 
> > > Awk Command
> > > https://linoxide.com/linux-command/awk-command-in-linux/  
> > 
> > The awk "command"? It's a language!
> > 
> > Walt
> 
> This is a ubiquitous and perpetual problem. Web-search for any kind of
> help on awk, and 90% of the replies do the whole thing as a one-liner.
> Code that should be five substantial lines of awk are treated as
> arguments. People discussing awk seem to judge their awk-worthiness by
> how complex their one-liners can get.
> 
> Awk is a beautiful, beautiful language for stream processing when
> there's not too much state involved. The implied outer-loop makes
> programs a level simpler. Awk's been around forever, long ago debugged
> and optimized. It's on every POSIX computer I've ever seen, although
> not necessarily quite the same version and feature set.

Awk's indeed a great language, but I never use it any more. Languages
like Perl and Python have similar feature sets, are just as easy to
use, and if you need to scale your script beyond something simple
there are huge libraries of packages to choose from.

I used to still use awk for splitting files since the syntax was a bit
simpler than Perl, but cut(1) does the simple cases even more simply,
and for anything else I use `perl -a`.

> The following is my awk program for printing every line of a file
> until, but not including, a line containing ARGV[1]:

I'd never consider writing this as a standalone program because (at
least for me) it doesn't come up very often, and because it's trivial
to write as a perl one-liner:

$ cat file | perl -pe 'last if /regex/'

As a bonus, that also works as

$ perl -pe 'last if /regex/' file

which your script doesn't support.

Attachment: signature.asc
Description: PGP signature

___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug