Category:TXR: Difference between revisions

From Rosetta Code
Content added Content deleted
No edit summary
m (Linkify, move the site into the language template)
Line 1: Line 1:
{{stub}}{{language}}
{{stub}}{{language
|site=http://www.nongnu.org/txr/}}


TXR[http://www.nongnu.org/txr/] is a new text extraction language implemented in C, running on Linux (and possibly other POSIX platforms).
TXR is a new text extraction language implemented in [[C]], running on [[Linux]] (and possibly other [[POSIX]] platforms).


Here is a very basic hello-world-type TXR query that re-implements the "free" utility:
Here is a very basic hello-world-type TXR query that re-implements the "free" utility:
Line 45: Line 46:
</pre>
</pre>


means, "Next, please switch to scanning the output of this echo command with some variables substituted in.
means, "Next, please switch to scanning the output of this echo command with some variables substituted in. Then capture entire first line of this command into the USED variable."
Then capture entire first line of this command into the USED variable."

Revision as of 16:25, 20 September 2011

This page is a stub. It needs more information! You can help Rosetta Code by filling it in!
Language
TXR
This programming language may be used to instruct a computer to perform a task.
Official website
See Also:


Listed below are all of the tasks on Rosetta Code which have been solved using TXR.

TXR is a new text extraction language implemented in C, running on Linux (and possibly other POSIX platforms).

Here is a very basic hello-world-type TXR query that re-implements the "free" utility:

<lang txr>#!/usr/bin/txr -f @(next "/proc/meminfo") @(skip) MemTotal:@/ +/@TOTAL kB MemFree:@/ +/@FREE kB Buffers:@/ +/@BUFS kB Cached:@/ +/@CACHED kB @(skip) SwapTotal:@/ +/@SWTOT kB SwapFree:@/ +/@SWFRE kB @(next `!echo $(( @TOTAL - @FREE ))`) @USED @(next `!echo $(( @USED - @BUFS - @CACHED ))`) @RUSED @(next `!echo $(( @FREE + @BUFS + @CACHED ))`) @RFREE @(next `!echo $(( @SWTOT - @SWFRE ))`) @SWUSE @(output)

              TOTAL         USED         FREE      BUFFERS       CACHED

Mem: @{TOTAL -12} @{USED -12} @{FREE -12} @{BUFS -12} @{CACHED -12} +/- buffers/cache: @{RUSED -12} @{RFREE -12} Swap: @{SWTOT -12} @{SWUSE -12} @{SWFRE -12} @(end)</lang>

Sample run:

$ ./meminfo.txr
               TOTAL         USED         FREE      BUFFERS       CACHED
Mem:          769280       647752       121528       160108       286844
+/- buffers/cache:         200800       568480
Swap:        1048568        18200      1030368

Arithmetic is not implemented in TXR as of version 035. The above example simply continues the pattern matching across invocations of echo to borrow the shell to do math. The command

@(next `!echo $(( @TOTAL - @FREE ))`)
@USED

means, "Next, please switch to scanning the output of this echo command with some variables substituted in. Then capture entire first line of this command into the USED variable."

Subcategories

This category has the following 3 subcategories, out of 3 total.

Pages in category "TXR"

The following 160 pages are in this category, out of 160 total.