#!/bin/sh # fluxes # RTH 11/01/07 # # AWK Math example, using one of Jon's early HW assignments # Some AWK variants (GAWK, NAWK, etc.) have different functions, so RTFM to see # Note that AWK log is really ln, so use identity that log_10(x) = ln(x)/ln(10) # Remember that $1 is the first column, $2 the second, and so on. # Also note the syntax of AWK in general: # 1. You don't have to declare variables or types, it does its best to pick # 2. awk 'BEGIN {Do before reading} {Do while reading} END {Duh}' IN > OUT # 2a. ** If you don't print anything, there won't be any output :) ** # 3. AWK is best for relatively simple, one liner-ish programs. # Anything more and you should seriously consider Perl or Python or # one of the higher scripted languages! # 3a. Intersting to note that limitations in both SED and AWK led to # the creation of Perl, which is like a script-variant of C. awk '{print $1,(-2.5)*(log($2)/log(10))-21.1}' vegaobs.dat > vega_stmag.dat awk '{f_nu=$2*$1^2*(1e-10)*(1/3e8) print $1,(-2.5)*(log(f_nu)/log(10))-48.6 }' vegaobs.dat > vega_abnu.dat # This is just for me, I have a perl/PGPLOT wrapper that takes care of most # mundane plotting tasks. Use whatever your heart desires to plot the output ~/plotter/template vegaobs.dat -2nd vega_stmag.dat -3rd vega_abnu.dat -line -yrange 3,-1.5 -label "Wavelength (\A),Magnitude,STMAG (Green) & ABNU (Blue)"