TextTools

A highly efficient collection of text manipulation functions written in C++ based on the .Net framework. It has been developed as an additional tool in the course of my master thesis at the Graz University of Technology.

You can specify an arbitrary amount of source text (.txt) files to work with.  Command line flags start with a “-“, whereas source files don’t. Command line flags are seperated by spaces and can occur in any order. In the following, usage options will be presented in greater detail.

Note: TextTools is not being maintained anymore. Nevertheless, you can still download the last version in the download section below.

USAGE

Using the command line version is pretty straight forward. Here is a simple example of how you can call Texttools from the command line:

Texttools -w=my_output_file.txt -s=asc -e=; -ed=my_extracted_lines.txt source.txt

This command does the following:

  1. reads in file “source.txt” (whereas blank lines are excluded by default)
  2. sorts the read lines from “source.txt” lexicographically ascending (default). Can be turned OFF by using flag -b=0
  3. extracts all characters from the lines until the delimiter “;” is found. If delimiter is not found the entire line is extracted (-e=;)
  4. writes the extracted lines to file “my_extracted_lines.txt” (-ef=my_extr…)
  5. writes the sorted lines from (2) back to “my_output_file.txt” (-w=my_out…)

FLAGS OVERVIEW

You can always get the flag overview by calling Texttools.exe without any flags:

Texttools.exe:

usage: Texttools

[-d=0]

[-e=delim [-ed=dest]]

[-o=delim [-od=dest]]

[-p= [-ps=src] [-pd=dest]]

[-r=expr [-rd=dest]]

[-s=0|asc|desc [-sd=dest]]

[-u=delim [-ud=dest]]

[-w=c|dest|s]

[src_files ...]

FLAGS EXPLANATION

-d:

  • if 0 statistics will NOT be displayed, is turned ON by default

-e:

  • extracts all (sub)strings from [src_files] up to the delimiter specified.
  • Use -ed to specify which destination filename to use, otherwise DEFAULT_EXTRACTION_FILE will be used

-o:

  • rotates strings from [src_files] until given delimiter. If delimiter is empty the entire line will be rotated.
  • Use -od to specify which destination filename to use, otherwise DEFAULT_ROTATION_FILE will be used

-p:

  • replaces (sub)string from [src_files] based on the rules file specified by the flag -ps.
  • Use -ps to specify which source filename to use, otherwise DEFAULT_RULE_FILE will be used.
  • Use -pd to specify which destination filename to use, otherwise DEFAULT_REPLACED_FILE will be used.

-s:

  • used to sort list read from src_files. NOTE that once -s flag is used the internal list will be sorted and the program will use the sorted list from this point onwards!
  • if 0 or empty list will NOT be sorted
  • if asc list is sorted lexicographic ASCending
  • if  desc list is sorted lexicographic DESCending
  • otherwise ERROR

-u:

  • used to uniquify list, i.e. removes all double entries
  • if empty simply removes all “equal” strings,
  • otherwise takes predicate based on flag specified [NOT AVAILABLE YET]
  • takes -ud if specified for destination filename to write removed lines to.
  • if empty DEFAULT_REMOVED_FILE is taken,
  • otherwise dest_filename is used

-w:

  • used to write list generated during reading of [src_files] to file specified.
  • If empty or not existent DEFAULT_OUTPUT_FILE is taken.
  • If s then the program will automatically write the output-lines to files which start the line’s leading character, i.e. a-z.txt and other.txt are used.
  • otherwise specified filename is taken (if it not already exists)
  • If c the output-lines will be printed to the commandline.

-r:

  • removes expression specified from [src_files] [NOT AVAILABLE YET]

List of default filenames

DEFAULT_OTHER_FILENAME other.txt

DEFAULT_OUTPUT_FILE output.txt

DEFAULT_EXTRACTION_FILE extracted.txt

DEFAULT_UNIFICATION_FILE unification.txt

DEFAULT_REMOVE_FILE removed.txt

DEFAULT_ROTATION_FILE rotated.txt

DEFAULT_RULES_FILE rules.txt

DEFAULT_REPLACE_FILE replaced.txt

Rules file

This file must have the following format:

old_expr | new_expr [ | begin_env [ | end_env ] ]

Explanation

Expressions can be simple replaced by other expression in context of the entire line.

With Texttools you can also replace expressions inside so-called environments.

An environment has a special beginning and an end (delimiters). This can either be a single character or an arbitrarely long string.

The environment is optional: If you do not specify an environment Texttools will simply replace ALL occurrences of old_expr by new_expr.

When specifying an environment you have to following options:

... [ | (EMPTY || *#*BOL*#* || left_delim) [ | (EMPTY || *#*EOL*#* || right_delim) ] ]

*#*BOL*#* stands for “begin of line”, meaning that old_expr must be the first word in the current line.

*#*EOL*#* stands for “end of line”, meaning that old_expr must be the last word in the current line.

Examples:

TEST|new will replace ALL occurrences of TEST with new in each line and is the same as TEST | new | *#*BOL*#* | *#*EOL*#*

TEST|new|*#*BOL*#* will replace ALL occurrences of TEST with new in each line only if TEST is the first word in the current line

TEST|new||*#*EOL*#* will replace ALL occurrences of TEST with new in each line only if TEST is the last word in the current line

Download

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.