Category:TXR: Difference between revisions

Content added Content deleted
(→‎Simple Query: [minor] Wording.)
(→‎Simple Query: Revised example: using built-in math that TXR now has.)
Line 52: Line 52:
<lang txr>#!/usr/bin/txr -f
<lang txr>#!/usr/bin/txr -f
@(next "/proc/meminfo")
@(next "/proc/meminfo")
@(define num (n))@\
@(skip)
@(local numtok)@{numtok /[0-9]+/}@(bind n @(int-str numtok 10))@\
MemTotal:@/ +/@TOTAL kB
@(end)
MemFree:@/ +/@FREE kB
@(gather)
Buffers:@/ +/@BUFS kB
Cached:@/ +/@CACHED kB
MemTotal: @(num TOTAL) kB
MemFree: @(num FREE) kB
@(skip)
SwapTotal:@/ +/@SWTOT kB
Buffers: @(num BUFS) kB
Cached: @(num CACHED) kB
SwapFree:@/ +/@SWFRE kB
SwapTotal: @(num SWTOT) kB
@(next `!echo $(( @TOTAL - @FREE ))`)
SwapFree: @(num SWFRE) kB
@USED
@(end)
@(next `!echo $(( @USED - @BUFS - @CACHED ))`)
@(bind USED @(- TOTAL FREE 10))
@RUSED
@(next `!echo $(( @FREE + @BUFS + @CACHED ))`)
@(bind RUSED @(- USED BUFS CACHED))
@(bind RFREE @(+ FREE BUFS CACHED))
@RFREE
@(next `!echo $(( @SWTOT - @SWFRE ))`)
@(bind SWUSE @(- SWTOT SWFRE))
@SWUSE
@(output)
@(output)
TOTAL USED FREE BUFFERS CACHED
TOTAL USED FREE BUFFERS CACHED