Skip to content

Linux Text Processing API

Linux text-processing pipelines for filtering, transforming and summarizing streamed text.

1 class · 6 methods

Text Commands

6 methods

POSIX text utilities commonly combined in pipelines.

grep [-i] [-v] [-E] [-n] [-r] pattern [file...]

Searches for lines matching a regular expression; -i case-insensitive, -v invert, -E extended, -r recursive.

Parameters

NameTypeDescription
patternregexPattern to match.
filestringFiles to search; reads stdin if omitted.

Returns

void

Example

linux
grep -nE 'function\s+\w+' src/*.ts
sed [-i] -e 'script' [file...]

Stream editor for filtering and transforming text; -i edits files in place.

Parameters

NameTypeDescription
scriptstringEditing commands, e.g. s/old/new/g.
filestringInput file(s).

Returns

void

Example

linux
sed -i 's/\r$//' *.sh
awk [-F sep] 'program' [file...]

Pattern-action scanning language; splits each record into fields and runs program per record.

Parameters

NameTypeDescription
sepstringField separator (default whitespace).
programstringPattern { action } pairs.

Returns

void

Example

linux
awk -F, '{ sum += $2 } END { print sum }' data.csv
sort [-n] [-r] [-u] [-k F[,F]] [file...]

Sorts lines of text; -n numeric, -r reverse, -u unique, -k key field(s).

Parameters

NameTypeDescription
filestringInput file(s); reads stdin if omitted.

Returns

void

Example

linux
sort -nrk 2 scores.txt | head -5
uniq [-c] [-d] [-u] [file]

Filters or reports adjacent repeated lines; usually preceded by sort. -c prefixes count.

Parameters

NameTypeDescription
filestringInput file; reads stdin if omitted.

Returns

void

Example

linux
sort access.log | uniq -c | sort -nr | head
tee [-a] file...

Reads from stdin and writes to stdout and the given files; -a appends instead of overwriting.

Parameters

NameTypeDescription
filestringOutput file(s).

Returns

void

Example

linux
npm test 2>&1 | tee build.log