This HTML automatically generated with rman for NEMO
Table of Contents

Name

txtpar - extract parameters from a text file, with optional math

Synopsis

txtpar in=text-file p0= p1= ...

Description

txtpar combines some of the often used combinations of standard Unix text filtering programs like grep(1) , awk(1) , and sed(1) , and with nemoinp(3NEMO) style math into one "simple" NEMO program. Although tabmath(1NEMO) can do some of this processing too, txtpar(1NEMO) ’s strength is processing multiple lines in a reduction style, instead of filtering. It often simplifies the esoteric syntax used in the grep/awk/sed pipes, but is much more limited.


     grep RA rsr.33551.driver.sum.txt  | head -1 | awk ’{print $4}’
vs.
     txtpar rsr.33551.driver.sum.txt p0=RA,1,4

Normally one parameter is extracted per p#= directive, in a word,row,col fashion. Future option will allow multiple col’s , but this is not implemented yet.

Comment lines in the input file are considered part of the text, they are not stripped out. Use tabcomment(1NEMO) first if you really need them removed.

Optionally additional math is allowed on the extracted parameters using nemoinp(1NEMO) style expressions. In this case, the parameters themselves are not output, but only the ones computed via expr=. See EXAMPLES below if you need both.

To extract values from a key=val style parameter file, use nemopars(8NEMO) .

Parameters

The following parameters are recognized in order; they may be given in any order if the keyword is also given. Use --help to confirm this man page is up to date.
in=in-file
input text file, containing marker words and numeric values to be parsed. No default.
expr=expr1,...
Optional expression(s), separated by commas, referencing the extracted parameters via the fie(3NEMO) parsing rules. By default no expression is needed and each parameter is output as they appeared in the text file, however when expr= is used, only those newly computed values are output. [Default: no expression given]
format=expression
A (printf(3) ) format specification applied to the computed expressions with which the parameters are written to output [Default: %g].
seed=seed
Integer initial seed in case random numbers have been used in the expression. If 0 is given, the time of the day will be used (see xrandom(3NEMO) for other special seed values) to initialize the random number generator. [Default: 0].
newline=t|f
Should a newline be used between output values. [Default: f]
maxline=max
In case a NEMO/unix pipe is used, the maximum number of lines will need to be specified. [Default: 10000]
p#=[word,]row,col,...
Parameter selection directive in the indexed keyword notation (e.g. p0=, p1=, p2=), see getparam(3NEMO) . word is the string to search on (with some limited grep syntax), but can be blank if all lines need to apply. row is an integer, and is the row-th occurance from the word match. 1 would be the first, 2 the 2nd, -1 the last, -2 the one but last etc. 0 is not an allowed row number. col is an integer, and designates the "column" to look for in the current row (line), 1 would be the first word, -1 the last etc. Multiple col will be allowed in a future version, but currently not available. 0 is not an allowed col number.

At least one parameter needs to be given: p0=.

Examples

Here is an example of extracting three values and converting them to two output values:
       txtpar in=example.txt expr="log(abs(%1)),log(abs(%3/%2))" format=%.3f
\
              p0=Worst,1,9  p1=QAC,1,3 p2=QAC,1,4
    
       cat example.txt
       Worst fractional energy loss dE/E = (E_t-E_0)/E_0 = 0.00146761 at
T = 1.28125
       QAC_STATS: - 0.039966 0.0274195 0.00185505 0.135854  0.799319 1  20
       

If both original values as well as newly computed expr= are desired in the output (this is the default behavior in tabmath(1NEMO) ), an extra pipe using tabmath(1NEMO) ) is needed. Here is an example to add the first column in the first two lines of a table in both forms, with and without the original values

      txtpar example.txt p0=1,1 p1=2,1 | tabmath - - %1+%2 format=%.3f
      txtpar example.txt %1+%2 %.3f p0=1,1 p1=2,1 

Caveats

This program is not intended for streaming very large files, as the file is read into memory for processing and each parameter could potentially cause a search through the file.

Todo

On the wishlist are relative row/col w.r.t. the matched word using an explicit + or - in front of the row or col:
     p0=word,+row,col
     p0=word,row,-col

See Also

grep(1) , awk(1) , nemopars(8NEMO) , tabmath(1NEMO) , tabrows(1NEMO) , tabcomment(1NEMO) , table(5NEMO) , run(1NEMO)

Author

Peter Teuben

Update History


27-dec-2021    V0.1 simple draft written - implemented simple version    PJT


Table of Contents