Making the best CLI programs - Programming On Unix

Users browsing this thread: 1 Guest(s)
pranomostro
Long time nixers
(04-06-2016, 05:01 AM)z3bra Wrote: Why so? Because you shouldn't "force yourself" and simply use what's available? It makes sense to do so. My point was more about the fact that using awk only to print specific columns is not efficient at all. We came to a point where people use awk ONLY for this specific purpose. That's what is bugging me there.

To come back to this: I think there is a reason why we have small programming languages as filters, sed, awk, heck, even regular expressions are a small language. Yes, using awk just to print columns means not using it's full capabilities, but I think that is okay. In the book 'The Awk programming language' the authors stated that awk was mostly used for quick one-liners, and then continued to say that it was also possible to write full-blown programs in it. So first purpose was really a tool for flexible one-liners.

And if you mean efficient in the sense of 'awk is not fast', I want to discuss that with you. Because I had a really hard time beating
a awk 4-liner with a optimised and specialized C program. awk is fast. Give it a try yourself and try to beat awk with C. I found it very hard.

awk is useful for simple tasks like printing columns, validating data and so on, for creating filters on the fly. In my opinion it plays well together with the rest of the environment.

I took a look at my history to show that awk can be really useful for that:

Code:
$ ./leyland | awk '{ print($2"^"$3"+"$3"^"$2"=="$1) }' | bc | g -v '^1$'
# this is a good example for awk's usage: rearranging fields and verifying a commands output
$ zcat data/test06.gz | ./genin | ./rcn | awk '$3<0.5'
# again, we use awk as a filter. sed would be too complicated here, and bc just doesn't cut it (mainly because of the lack of -e)
$ ./ffstats bzip2 test/*.png | awk '$1>1 { print($1*10) }'  | sed 's/\..*//' | stag
# filtering and transforming the input would have been quite tedious in C, at least more than here


Messages In This Thread
Making the best CLI programs - by venam - 23-05-2016, 02:13 AM
RE: Making the best CLI programs - by jkl - 23-05-2016, 04:49 AM
RE: Making the best CLI programs - by z3bra - 23-05-2016, 10:20 AM
RE: Making the best CLI programs - by jkl - 23-05-2016, 10:51 AM
RE: Making the best CLI programs - by pranomostro - 28-05-2016, 10:50 AM
RE: Making the best CLI programs - by z3bra - 29-05-2016, 10:52 AM
RE: Making the best CLI programs - by josuah - 01-06-2016, 10:40 AM
RE: Making the best CLI programs - by z3bra - 01-06-2016, 01:15 PM
RE: Making the best CLI programs - by z3bra - 02-06-2016, 03:27 AM
RE: Making the best CLI programs - by jaagr - 04-06-2016, 03:10 AM
RE: Making the best CLI programs - by z3bra - 04-06-2016, 05:01 AM
RE: Making the best CLI programs - by venam - 14-09-2016, 01:58 PM
RE: Making the best CLI programs - by jkl - 14-09-2016, 02:03 PM
RE: Making the best CLI programs - by venam - 14-09-2016, 02:05 PM
RE: Making the best CLI programs - by venam - 12-10-2016, 12:52 AM
RE: Making the best CLI programs - by apk - 12-10-2016, 12:34 PM
RE: Making the best CLI programs - by acg - 12-10-2016, 09:57 PM
RE: Making the best CLI programs - by pranomostro - 13-10-2016, 05:18 AM
RE: Making the best CLI programs - by z3bra - 13-10-2016, 08:53 AM
RE: Making the best CLI programs - by pranomostro - 13-10-2016, 02:12 PM
RE: Making the best CLI programs - by josuah - 17-10-2016, 05:16 PM
RE: Making the best CLI programs - by venam - 25-11-2016, 04:07 PM
RE: Making the best CLI programs - by freem - 04-12-2020, 11:27 AM
RE: Making the best CLI programs - by venam - 21-06-2021, 02:32 AM
RE: Making the best CLI programs - by seninha - 21-06-2021, 06:23 AM
RE: Making the best CLI programs - by venam - 21-06-2021, 07:41 AM
RE: Making the best CLI programs - by z3bra - 24-06-2021, 04:59 AM
RE: Making the best CLI programs - by jkl - 12-10-2021, 05:59 AM
RE: Making the best CLI programs - by freem - 15-10-2021, 12:49 PM
RE: Making the best CLI programs - by z3bra - 17-10-2021, 07:54 AM
RE: Making the best CLI programs - by Kohaku - 03-11-2023, 01:18 PM
RE: Making the best CLI programs - by neeasade - 08-11-2023, 02:29 PM
RE: Making the best CLI programs - by jkl - 09-11-2023, 10:54 PM
RE: Making the best CLI programs - by rocx - 28-11-2023, 08:11 PM