Input Macros
The macros in the sample input_macros.cfg configuration file below are for script data input. You would use these to, for example, preprocess or reformat input, as shortcuts for reading data from files, etc.
/////////////////////////////////////////////////////////////////////////////// // input macros - script input /////////////////////////////////////////////////////////////////////////////// behead(N) =sed '1,(N)d' // behead chops off the first (N) lines // of input; e.g., // // input proc "=swap -l | =behead(1)" // // excludes: // // swapfile dev swaplo blocks free // // and yields (for example): // // /dev/dsk/c0t0d0s1 136,1 16 2097632 2097632 /////////////////////////////////////////////////////////////////////////////// onecol =tr ' ' '\\012' // onecol takes a string of tokens separated // by spaces as input and outputs them line // by line in a single column; e.g., // // input proc "=echo 'one two three' | =onecol" // // yields the input stream: // // one // two // three /////////////////////////////////////////////////////////////////////////////// oneline =tr '\\012' ' ' // oneline takes a series of lines as input // and outputs them as one long string; e.g., // // input proc "=df | =behead(1) | =oneline" // // yields an input stream like so: // // /dev/dsk/c0t3d0s0 23063 16559 4204 80% / // /dev/dsk/c0t3d0s6 210895 185378 4437 98% /usr ... /////////////////////////////////////////////////////////////////////////////// readvals(F, V, S, N) // open the file (F), for each input line, #split() // on separator(s) (S) into (N) fields, assign to // associative array (V)[], with the first field in // the referenced file as the key // (F) is the file (e.g., =passwd; without quotes) // (V) is the variable name (e.g., pfield) // (S) is the field separator (e.g, ":"; with quotes) // (N) is the number of assigned values per line, // (e.g., 6; note that (N) should be one less // than the actual number of data items per line, // since the first data item is the key, and all // remaining items are the assigned values) // sample use: =readvals(=objdir/ProcessTimes.obj, minsproc, " ", 3) if #fopen(READVALS, "(F)", "r") != #err() while #read(READVALS) > 0 set #nrv = #split($rdlin, (S)) - 1 #ifdef debug if #nrv < (N) =outputmail "Too few vals ($text(#nrv)): $rdlin" fi #endifdef for #irv=1 #irv<=(N) #irv+=1 set $(V)["$trim($1) $text(#irv)"] = $trim($[#irv+1]) endfor endwhile do #fclose(READVALS) #ifdef debug for $krv in #keys($(V)) output "$krv $(V)[$krv]" endfor #endifdef else output mail "Can't open (F) for reading!" quit fi ///////////////////////////////////////////////////////////////////////////////
For more examples, see Samples.