2 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns=
"http://www.w3.org/1999/xhtml">
5 <title>td-alter - Add new columns and fields to tabular data stream, and modify value of existing fields.
</title>
6 <meta http-equiv=
"content-type" content=
"text/html; charset=utf-8" />
7 <link rev=
"made" href=
"mailto:root@localhost" />
15 <li><a href=
"#NAME">NAME
</a></li>
16 <li><a href=
"#USAGE">USAGE
</a></li>
17 <li><a href=
"#DESCRIPTION">DESCRIPTION
</a></li>
18 <li><a href=
"#EXAMPLES">EXAMPLES
</a></li>
19 <li><a href=
"#OPTIONS">OPTIONS
</a></li>
20 <li><a href=
"#REFERENCES">REFERENCES
</a></li>
23 <h1 id=
"NAME">NAME
</h1>
25 <p>td-alter - Add new columns and fields to tabular data stream, and modify value of existing fields.
</p>
27 <h1 id=
"USAGE">USAGE
</h1>
29 <p>td-alter
<i>COLUMN
</i>=
<i>EXPR
</i> [
<i>COLUMN
</i>=
<i>EXPR
</i> [
<i>COLUMN
</i>=
<i>EXPR
</i> [...]]]
</p>
31 <h1 id=
"DESCRIPTION">DESCRIPTION
</h1>
33 <p>On each data row, sets field in
<i>COLUMN
</i> to the value resulted by
<i>EXPR
</i> Perl expression.
</p>
35 <p>In
<i>EXPR
</i>, you may refer to other fields by
<code>$F{NAME}
</code> where
<i>NAME
</i> is the column name; or by
<code>$F[INDEX]
</code> where
<i>INDEX
</i> is the
0-based column index number. Furthermore you may refer to uppercase alpha-numeric field names, simply by bareword
<code>COLUMN
</code>, well, enclosed in paretheses like
<code>(COLUMN)
</code> to avoid parsing unambiguity in Perl. It
's possible because these column names are set up as subroutines internally.
</p>
37 <p>Topic variable (
<code>$_
</code>) initially is set to the current value of
<i>COLUMN
</i> in
<i>EXPR
</i>. So for example
<code>N=
'-$_
'</code> makes the field N the negative of itself.
</p>
39 <p>You can create new columns simply by referring to a
<i>COLUMN
</i> name that does not exist yet. You can refer to an earlier defined
<i>COLUMN
</i> in subsequent
<i>EXPR
</i> expressions.
</p>
41 <h1 id=
"EXAMPLES">EXAMPLES
</h1>
43 <p>Add new columns: TYPE and IS_BIGFILE. IS_BIGFILE depends on previously defined TYPE field.
</p>
45 <pre><code>ls -l | td-trans-ls | td-alter TYPE=
'substr MODE,
0,
1' IS_BIGFILE=
'SIZE
>10000000 && TYPE ne
"d
" ?
"yes
" :
"no
"'</code></pre>
47 <p>Strip sub-seconds and timezone from DATETIME field:
</p>
49 <pre><code>TIME_STYLE=full-iso ls -l | td-trans-ls | td-alter DATETIME=
's/\..*//; $_
'</code></pre>
51 <h1 id=
"OPTIONS">OPTIONS
</h1>
55 <dt id=
"H---no--header">-H, --no--header
</dt>
58 <p>do not show headers
</p>
61 <dt id=
"h---header">-h, --header
</dt>
64 <p>show headers (default)
</p>
69 <h1 id=
"REFERENCES">REFERENCES
</h1>
71 <p>"Alter
" in td-alter comes from SQL. td-alter(
1) can change the
"table
" column layout. But contrary to SQL
's ALTER TABLE, td-alter(
1) can modify the records too, so akin to SQL UPDATE as well.
</p>