Hacker News new | past | comments | ask | show | jobs | submit login
Basic Scripting with Awk and Gnuplot (cyberchris.xyz)
103 points by thevirtuoso1973 on Jan 21, 2021 | hide | past | favorite | 9 comments



Beware when piping awk | gnuplot or especially awk | awk: when printing numbers, awk by default prints them with something like %.6g, which can lose important amounts of precision. There are two ways this can happen. Firstly when numbers are implicitly converted to strings, eg for concatenation; and secondly when they are printed directly. These conversations are controlled by two different variables which may be set to printf directives to get higher precision.


I note with interest the article links to: https://ferd.ca/awk-in-20-minutes.html

Very succinct quickstart guide.


I want to use gnuplot more, but I generally find myself spending too much time messing with the plot styles to get something I sort of like.

Can anyone point to some pretty styles they've come across?

Here is one I used a while ago: Pretty Plots with Gnuplot [0]

[0]: https://edg.uchicago.edu/tutorials/pretty_plots_with_gnuplot...


Some problems: the colours are not that great, and also not colourblind-safe. And most grating of all: why are the tics light gray and not black! It's very hard to read.



Just curious but why go for gnuplot (and awk) rather than python or R? At some point you run up to some limit where you want a bit more capability. I don't know that the learning curve is that much less for awk + gnuplot?


Gnuplot (and awk) have several advantages. It’s faster, especially for large datasets; it’s language-independent and can be used through pipes with any language, so the plotting solution you develop can go with you as you change your simulation language; it’s designed to be automated, plot over the network, etc.


There is no need to initialize variables with -v. You could just do:

    awk '/Time/{printf("%d %s ", ++j, $3)} ...


Or use a begin block: 'BEGIN { j = 1 } /Time/ … '

I find it best to restrict the use -v to injecting environment variables into my awk scripts.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: