Strings strings

String manipulation utilities — file reversal, edit distance, vowel stripping, and readability analysis
Pixelbadger Toolkit — pbtk strings← all topics

reverse

Reads the entire content of a file and writes it back in reverse character order. The reversal operates on the raw character sequence of the file — Unicode code points are preserved, but byte-order marks and newline conventions are not adjusted.

$ pbtk strings reverse --in-file input.txt --out-file reversed.txt
flowchart LR A["input.txt\n\"Hello, world!\""] --> R["Reverse\ncharacter sequence"] R --> B["reversed.txt\n\"!dlrow ,olleH\""]
OptionRequiredDescription
--in-fileYesPath to the input file to reverse
--out-fileYesPath to write the reversed content

levenshtein-distance

Computes the Levenshtein (edit) distance between two strings: the minimum number of single-character insertions, deletions, or substitutions required to transform one string into the other. Each argument can be a literal string value or a file path — if a path resolves to an existing file its contents are used as the string.

$ pbtk strings levenshtein-distance --string1 "kitten" --string2 "sitting"
flowchart LR S1["--string1\n(literal or file path)"] --> CALC["Dynamic programming\nmatrix O(m × n)"] S2["--string2\n(literal or file path)"] --> CALC CALC --> OUT(["stdout: distance"])

Algorithm

The implementation uses the standard dynamic-programming approach. A matrix of size (m+1) × (n+1) is built where each cell [i][j] stores the edit distance between the first i characters of string 1 and the first j characters of string 2.

cost = 0 if s1[i] == s2[j], else 1 matrix[i][j] = min( matrix[i-1][j] + 1, // deletion matrix[i][j-1] + 1, // insertion matrix[i-1][j-1] + cost // substitution )
OptionRequiredDescription
--string1YesFirst string or path to a file whose contents are used
--string2YesSecond string or path to a file whose contents are used

abjadify

Strips English vowels (a e i o u, upper and lower case) from every word in a file, mimicking the consonant-heavy style of abjad writing systems used in Arabic, Hebrew, and related scripts. Single-vowel words (a and i) are preserved intact because they would become empty strings otherwise, losing meaning.

$ pbtk strings abjadify --in-file text.txt --out-file abjadified.txt
flowchart LR IN["input.txt\n\"I like a quiet place\""] --> SPLIT["Split on\nnon-letter boundaries"] SPLIT --> CHECK{"Single-vowel\nword?"} CHECK -- Yes --> KEEP["Preserve as-is\n'I', 'a'"] CHECK -- No --> STRIP["Remove vowels\n'like' → 'lk'\n'quiet' → 'qt'\n'place' → 'plc'"] KEEP --> JOIN["Reassemble"] STRIP --> JOIN JOIN --> OUT["output.txt\n\"I lk a qt plc\""]
Whitespace, punctuation, and non-letter characters are passed through unchanged, so the output preserves the original document structure.
OptionRequiredDescription
--in-fileYesPath to the input plain-text file
--out-fileYesPath to write the abjadified output

flesch-reading-ease

Analyses a plain-text file and produces a Flesch Reading Ease score — a well-established formula that estimates how easy a passage is to read based on sentence length and word complexity (syllable count). Higher scores indicate easier text; lower scores indicate more complex writing.

$ pbtk strings flesch-reading-ease --in-file document.txt

Formula

score = 206.835 − (1.015 × words/sentences) − (84.6 × syllables/words)

The raw score is clamped to the range [0, 100]. Syllables are counted using a vowel-group heuristic: each contiguous run of vowel characters (a e i o u y) counts as one syllable, with a correction for silent trailing -e. Every word is counted as having at least one syllable.

Readability Bands

90 – 100
Very easy

Easily understood by an average 11-year-old.

80 – 89
Easy

Conversational English.

70 – 79
Fairly easy

Aimed at 13-year-old readers.

60 – 69
Standard

Plain English, easily understood.

50 – 59
Fairly difficult

Suited to high school or college level.

30 – 49
Difficult

Best understood by college graduates.

0 – 29
Very confusing

Best understood by university graduates.

Output

Five values are printed to stdout:

Flesch Reading Ease: 65.34 Readability: Standard Sentences: 12 Words: 198 Syllables: 301
OptionRequiredDescription
--in-fileYesPath to the plain-text file to analyse

report

Performs a full text analysis of the input, producing a comprehensive report that includes word count, sentence averages, estimated page count, Flesch Reading Ease score, readability band, reading time, and more. Input can be provided as a file path or as a direct string value.

$ pbtk strings report --in-file article.txt
$ pbtk strings report --string "The quick brown fox jumps over the lazy dog."
Exactly one of --in-file or --string must be provided.
OptionRequiredDescription
--in-fileOne ofPath to the input plain-text file to analyse
--stringOne ofDirect text string to analyse

Command Reference

Command Required options Optional options Output
strings reverse --in-file --out-file Reversed content written to --out-file
strings levenshtein-distance --string1 --string2 Integer distance printed to stdout
strings abjadify --in-file --out-file Vowel-stripped text written to --out-file
strings flesch-reading-ease --in-file Score, readability band, and counts printed to stdout
strings report --in-file or --string Full text analysis report printed to stdout