Text Commands
6 methodsPOSIX 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
| Name | Type | Description |
|---|---|---|
| pattern | regex | Pattern to match. |
| file | string | Files to search; reads stdin if omitted. |
Returns
void
Example
linux
grep -nE 'function\s+\w+' src/*.tssed [-i] -e 'script' [file...]Stream editor for filtering and transforming text; -i edits files in place.
Parameters
| Name | Type | Description |
|---|---|---|
| script | string | Editing commands, e.g. s/old/new/g. |
| file | string | Input file(s). |
Returns
void
Example
linux
sed -i 's/\r$//' *.shawk [-F sep] 'program' [file...]Pattern-action scanning language; splits each record into fields and runs program per record.
Parameters
| Name | Type | Description |
|---|---|---|
| sep | string | Field separator (default whitespace). |
| program | string | Pattern { action } pairs. |
Returns
void
Example
linux
awk -F, '{ sum += $2 } END { print sum }' data.csvsort [-n] [-r] [-u] [-k F[,F]] [file...]Sorts lines of text; -n numeric, -r reverse, -u unique, -k key field(s).
Parameters
| Name | Type | Description |
|---|---|---|
| file | string | Input file(s); reads stdin if omitted. |
Returns
void
Example
linux
sort -nrk 2 scores.txt | head -5uniq [-c] [-d] [-u] [file]Filters or reports adjacent repeated lines; usually preceded by sort. -c prefixes count.
Parameters
| Name | Type | Description |
|---|---|---|
| file | string | Input file; reads stdin if omitted. |
Returns
void
Example
linux
sort access.log | uniq -c | sort -nr | headtee [-a] file...Reads from stdin and writes to stdout and the given files; -a appends instead of overwriting.
Parameters
| Name | Type | Description |
|---|---|---|
| file | string | Output file(s). |
Returns
void
Example
linux
npm test 2>&1 | tee build.log