Text Utilities

/REQUIRE textutil.tf


The library file textutil.tf defines several unix-like commands that are particularly convenient when used with the %| pipe to redirect their input or output.

In the descriptions below, filename is the name of a file, and in and out are handles of tfio streams. When in is optional, its default is tfin.

/fgrep [-cvi] pattern
/grep [-cv] pattern
/egrep [-cvi] pattern
These commands search tfin for lines that match the given pattern, and by default prints those lines. For /fgrep, a line must contain pattern to match; for /grep, the entire line must match the glob pattern pattern; for /egrep, it must match the regexp pattern pattern.
Options:
-c
print only the count of matching lines.
-v
select only non-matching lines.
-i
ignore case (for /fgrep and /egrep only; /grep always ignores case).
Note: these commands are not compatible with those defined in the old library file grep.tf.

/readfile filename
Reads lines from filename and writes them to tfout.

/writefile [-a] filename
Reads lines from tfin and writes them to file filename.
Options:
-a
append to file instead of overwriting.

/head [-ncount] [in]
Reads the first count (default 10) lines from in or tfin and writes them to tfout.

/wc [-lwc] [in]
Reads lines from in or tfin and prints the count of lines, space-separated words, and characters that were read.
Options:
-l
Print the count of lines only.
-w
Print the count of words only.
-c
Print the count of characters only.

/tee out
Reads lines from tfin and echoes them to out and tfout.

/copyio in out
Reads lines from in and writes them to out. This can be useful, for example, when you want to send text from a tfio stream to a command that reads only tfin:
    /copyio in o %| /command
    

/fmt
Copies tfin to tfout, with adjacent non-blank lines joined.

/uniq
Copies tfin to tfout, with adjacent duplicate lines removed.

/randline [in]
Copies one randomly selected line from in or tfin to tfout.


See: tfio, evaluation, substitution, oldgrep


Back to index
Back to tf home page
Copyright © 1998, 1999, 2002, 2003, 2004, 2005, 2006-2007 Ken Keys