Use it to search logs, extract fields from command output, or transform configuration files.
Text Processing
Text processing tools read and transform text streams: grep (search), sed (edit), awk (fields and logic), cut, sort, uniq, tr, wc, head/tail, jq for JSON.
1. Look at a sample: head -20 <file>.
2. Filter: grep the lines you need.
3. Extract: awk/cut the fields.
4. Aggregate: sort | uniq -c | sort -rn | head.
5. Edit in place only with a backup: sed -i.bak.
input text → filter → extract fields → transform → aggregate → output
For Text Processing, continue with the first unproven Topic check: Capture a representative raw input sample including edge cases, delimiters, whitespace, empty fields and non-ASCII/binary cases. If that boundary is healthy, advance to the adjacent check: Run each selection/transformation stage separately and compare record counts and sample outputs before composing the pipeline. Preserve the same host/time/identity scope and rerun the original workload before accepting recovery.
Continue only after interpreting the current observation.Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
catPrimary Commands
Configuration and operational commands for this Topic.
catReferenceConcatenate files or standard input and write the byte stream to standard output.
Use when: Primary lookup intent: inspect. Use cat when the lookup goal is to concatenate files or standard input and write the byte stream to standard output. Tie the result to the same host, namespace, user identity and time window as the symptom.
Quick note: Output review: healthy and suspicious cues are command-specific interpretation boundaries, not fixed literal output samples. Intent class: inspect. Safety class: read_only. Intent describes the primary lookup role; safety remains command-family capability and can be higher than a read-only invocation. cat is documented as an operational lookup primitive under Text Processing. The canonical leaf intentionally represents the command family; options remain distribution/tool-version specific.
lessReferencePage through text interactively without loading the entire input into the terminal.
Use when: Primary lookup intent: inspect. Use less when the lookup goal is to page through text interactively without loading the entire input into the terminal. Tie the result to the same host, namespace, user identity and time window as the symptom.
Quick note: Output review: healthy and suspicious cues are command-specific interpretation boundaries, not fixed literal output samples. Intent class: inspect. Safety class: read_only. Intent describes the primary lookup role; safety remains command-family capability and can be higher than a read-only invocation. less is documented as an operational lookup primitive under Text Processing. The canonical leaf intentionally represents the command family; options remain distribution/tool-version specific.
headReferenceRead the first requested lines or bytes from one or more inputs.
Use when: Primary lookup intent: inspect. Use head when the lookup goal is to read the first requested lines or bytes from one or more inputs. Tie the result to the same host, namespace, user identity and time window as the symptom.
Quick note: Output review: healthy and suspicious cues are command-specific interpretation boundaries, not fixed literal output samples. Intent class: inspect. Safety class: read_only. Intent describes the primary lookup role; safety remains command-family capability and can be higher than a read-only invocation. head is documented as an operational lookup primitive under Text Processing. The canonical leaf intentionally represents the command family; options remain distribution/tool-version specific.
tailReferenceRead the end of a file or follow appended data as it arrives.
Use when: Primary lookup intent: troubleshoot. Use tail when the lookup goal is to read the end of a file or follow appended data as it arrives. Tie the result to the same host, namespace, user identity and time window as the symptom.
Quick note: Output review: healthy and suspicious cues are command-specific interpretation boundaries, not fixed literal output samples. Intent class: troubleshoot. Safety class: read_only. Intent describes the primary lookup role; safety remains command-family capability and can be higher than a read-only invocation. tail is documented as an operational lookup primitive under Text Processing. The canonical leaf intentionally represents the command family; options remain distribution/tool-version specific.
grepReferenceSelect lines whose text matches a literal or regular-expression pattern.
Use when: Primary lookup intent: troubleshoot. Use grep when the lookup goal is to select lines whose text matches a literal or regular-expression pattern. Tie the result to the same host, namespace, user identity and time window as the symptom.
Quick note: Output review: healthy and suspicious cues are command-specific interpretation boundaries, not fixed literal output samples. Intent class: troubleshoot. Safety class: read_only. Intent describes the primary lookup role; safety remains command-family capability and can be higher than a read-only invocation. grep is documented as an operational lookup primitive under Text Processing. The canonical leaf intentionally represents the command family; options remain distribution/tool-version specific.
sortReferenceOrder text records according to lexical, numeric, key or locale rules.
Use when: Primary lookup intent: inspect. Use sort when the lookup goal is to order text records according to lexical, numeric, key or locale rules. Tie the result to the same host, namespace, user identity and time window as the symptom.
Quick note: Output review: healthy and suspicious cues are command-specific interpretation boundaries, not fixed literal output samples. Intent class: inspect. Safety class: read_only. Intent describes the primary lookup role; safety remains command-family capability and can be higher than a read-only invocation. sort is documented as an operational lookup primitive under Text Processing. The canonical leaf intentionally represents the command family; options remain distribution/tool-version specific.
uniqReferenceCollapse or count adjacent duplicate lines in an already grouped text stream.
Use when: Primary lookup intent: inspect. Use uniq when the lookup goal is to collapse or count adjacent duplicate lines in an already grouped text stream. Tie the result to the same host, namespace, user identity and time window as the symptom.
Quick note: Output review: healthy and suspicious cues are command-specific interpretation boundaries, not fixed literal output samples. Intent class: inspect. Safety class: read_only. Intent describes the primary lookup role; safety remains command-family capability and can be higher than a read-only invocation. uniq is documented as an operational lookup primitive under Text Processing. The canonical leaf intentionally represents the command family; options remain distribution/tool-version specific.
cutReferenceExtract selected byte, character or delimiter-separated fields from each input line.
Use when: Primary lookup intent: inspect. Use cut when the lookup goal is to extract selected byte, character or delimiter-separated fields from each input line. Tie the result to the same host, namespace, user identity and time window as the symptom.
Quick note: Output review: healthy and suspicious cues are command-specific interpretation boundaries, not fixed literal output samples. Intent class: inspect. Safety class: read_only. Intent describes the primary lookup role; safety remains command-family capability and can be higher than a read-only invocation. cut is documented as an operational lookup primitive under Text Processing. The canonical leaf intentionally represents the command family; options remain distribution/tool-version specific.
trReferenceTranslate, squeeze or delete characters in a byte or character stream.
Use when: Primary lookup intent: inspect. Use tr when the lookup goal is to translate, squeeze or delete characters in a byte or character stream. Tie the result to the same host, namespace, user identity and time window as the symptom.
Quick note: Output review: healthy and suspicious cues are command-specific interpretation boundaries, not fixed literal output samples. Intent class: inspect. Safety class: read_only. Intent describes the primary lookup role; safety remains command-family capability and can be higher than a read-only invocation. tr is documented as an operational lookup primitive under Text Processing. The canonical leaf intentionally represents the command family; options remain distribution/tool-version specific.
wcReferenceCount lines, words, bytes or characters in text input.
Use when: Primary lookup intent: inspect. Use wc when the lookup goal is to count lines, words, bytes or characters in text input. Tie the result to the same host, namespace, user identity and time window as the symptom.
Quick note: Output review: healthy and suspicious cues are command-specific interpretation boundaries, not fixed literal output samples. Intent class: inspect. Safety class: read_only. Intent describes the primary lookup role; safety remains command-family capability and can be higher than a read-only invocation. wc is documented as an operational lookup primitive under Text Processing. The canonical leaf intentionally represents the command family; options remain distribution/tool-version specific.
sedReferenceTransform text streams with scripted substitutions, selections and line-oriented edits.
Use when: Primary lookup intent: configure. Use sed when the lookup goal is to transform text streams with scripted substitutions, selections and line-oriented edits. Tie the result to the same host, namespace, user identity and time window as the symptom.
Quick note: Post-change verification for sed: Diff/read back the edited content and rerun the parser/service/workload that consumes it. Output review: healthy and suspicious cues are command-specific interpretation boundaries, not fixed literal output samples. Intent class: configure. Safety class: changes_state. Intent describes the primary lookup role; safety remains command-family capability and can be higher than a read-only invocation. sed is documented as an operational lookup primitive under Text Processing. The canonical leaf intentionally represents the command family; options remain distribution/tool-version specific.
awkReferenceProcess structured text records using field-aware patterns, expressions and actions.
Use when: Primary lookup intent: inspect. Use awk when the lookup goal is to process structured text records using field-aware patterns, expressions and actions. Tie the result to the same host, namespace, user identity and time window as the symptom.
Quick note: Output review: healthy and suspicious cues are command-specific interpretation boundaries, not fixed literal output samples. Intent class: inspect. Safety class: read_only. Intent describes the primary lookup role; safety remains command-family capability and can be higher than a read-only invocation. awk is documented as an operational lookup primitive under Text Processing. The canonical leaf intentionally represents the command family; options remain distribution/tool-version specific.
xargsReferenceBuild command invocations from standard-input items while controlling batching and quoting.
Use when: Primary lookup intent: configure. Use xargs when the lookup goal is to build command invocations from standard-input items while controlling batching and quoting. Tie the result to the same host, namespace, user identity and time window as the symptom.
Quick note: Post-change verification for xargs: Reproduce the item set safely and verify every changed target plus the original aggregate workload. Output review: healthy and suspicious cues are command-specific interpretation boundaries, not fixed literal output samples. Intent class: configure. Safety class: changes_state. Intent describes the primary lookup role; safety remains command-family capability and can be higher than a read-only invocation. xargs is documented as an operational lookup primitive under Text Processing. The canonical leaf intentionally represents the command family; options remain distribution/tool-version specific.
diffReferenceCompare two files or directory trees and report line-oriented differences.
Use when: Primary lookup intent: verify. Use diff when the lookup goal is to compare two files or directory trees and report line-oriented differences. Tie the result to the same host, namespace, user identity and time window as the symptom.
Quick note: Output review: healthy and suspicious cues are command-specific interpretation boundaries, not fixed literal output samples. Intent class: verify. Safety class: read_only. Intent describes the primary lookup role; safety remains command-family capability and can be higher than a read-only invocation. diff is documented as an operational lookup primitive under Text Processing. The canonical leaf intentionally represents the command family; options remain distribution/tool-version specific.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Operational evidence path Verify boundary
raw input/source → bytes/encoding + record delimiters → shell quoting/expansion → filter/parser/transform stage(s) → stdout/stderr + exit status per stage → final text/data contract → downstream consumer/decision
Healthy evidence: representative input including edge cases produces the expected byte/record/field output, every relevant pipeline stage is successful, and the downstream consumer interprets it correctly.
Step 2 Commands Verify boundary
grep -E 'error|fail' app.log
awk '{print $1}' access.log | sort | uniq -c | sort -nr | head
sed -n '10,20p' file
cut -d: -f1 /etc/passwd
Step 3 Verification and output interpretation Verify boundary
Verification path. Reproduce with the same shell binary and mode, then inspect expansion and command resolution before changing data. Use tracing carefully to observe commands after expansion without exposing secrets. Validate exit status at the correct pipeline stage, check file descriptors/redirections, and test representative input including whitespace, glob characters and empty values. For text tools, record locale and regex dialect. Verify the external effect of the script, not merely that parsing completed.
Existing fast checks for this Topic. - Capture a representative raw input sample including edge cases, delimiters, whitespace, empty fields and non-ASCII/binary cases.
- Run each selection/transformation stage separately and compare record counts and sample outputs before composing the pipeline.
- Pin locale/encoding and quote patterns/arguments so the shell does not transform them before the text-processing tool receives them.
- Verify the final output against an expected oracle before passing it to a mutating command or automated decision.
Verification chain. raw input/source → bytes/encoding + record delimiters → shell quoting/expansion → filter/parser/transform stage(s) → stdout/stderr + exit status per stage → final text/data contract → downstream consumer/decision
Step 4 Failure modes and next checks Narrow the fault
Suspicious evidence: formatting, locale, quoting or a failed upstream stage changes the dataset while the last command still exits successfully.
Text-processing evidence requires showing that the final stream has the expected records/fields/content under the actual locale/encoding and that upstream stage failures cannot be silently accepted.
Next check: Continue from the first step that has not been verified: capture the exact shell-delivered argv/streams or resolved object, verify the effective target state, change only the demonstrated cause, then repeat the original consumer/script/workload and adjacent regression checks.
Step 5 Common mistakes Narrow the fault
- Using
grepwithout-Ffor literal strings with dots. sed -iwithout a backup on important files.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
Subtopics
Go one level deeper into this subject.
Build pipelines step by step and check each stage's output. Use sed -i.bak to keep a backup when editing in place. For JSON use jq, not grep. Locale affects sort order (LC_ALL=C sort).
grep -E '<regex>' <file>— matching linesawk '{print $1, $5}' <file>— selected fieldssed -n '/start/,/end/p' <file>— lines between two patternssort | uniq -c | sort -rn— count and rank valuesjq '.items[].name' <file.json>— fields from JSON
ReferenceWhat it is1 section · depth on demand
Core model
Define the input encoding, record delimiter, field structure and expected output before building a pipeline. Evaluate each stage independently, preserve stderr separately when needed, and account for quoting, locale, binary/NUL data and xargs argument construction before using transformed output as control input.
ReferenceImportant terms & boundaries5 sections · depth on demand
What this shows and what it does not
Text-processing evidence requires showing that the final stream has the expected records/fields/content under the actual locale/encoding and that upstream stage failures cannot be silently accepted.
In depth
Text processing with awk: fields, patterns and summaries
Many Linux tools produce text in columns, and awk is built to process it. The POSIX awk(1p) manual page describes the model:
- awk reads its input one record at a time, normally one line.
- It splits each record into fields:
$1,$2and so on, with$0the whole record. - It runs every
pattern { action }pair whose pattern matches. A missing pattern matches every record. BEGINandENDblocks run before the first record and after the last.
Built-in variables include NR (the record number), NF (the number of fields), FS (the field separator, default whitespace, set with -F) and OFS (the output separator). -v passes variables in.
The text toolbox
| Tool | Best at |
|---|---|
grep | Selecting lines that match a pattern |
sed | Editing streams: substitutions, deleting and printing line ranges |
awk | Working with fields, conditions, counting and summing |
cut | Simple fixed fields |
sort, uniq -c | Ordering and counting |
tr | Translating or deleting characters |
wc | Counting lines, words, bytes |
jq | JSON (awk and sed aren't JSON parsers) |
awk patterns
| Task | Command |
|---|---|
| Print columns 1 and 3 | awk '{print $1, $3}' |
| Colon-separated file | awk -F: '$3 >= 1000 {print $1}' /etc/passwd |
| Filter on a value | awk '$9 >= 500' access.log |
| Sum a column | awk '{s += $10} END {print s}' |
| Count by key | awk '{n[$1]++} END {for (k in n) print n[k], k}' |
| Last field | awk '{print $NF}' |
| Skip a header line | awk 'NR > 1' |
| Pass a shell value safely | awk -v lim="$LIMIT" '$5 > lim' |
host$ awk -F: '$3 >= 1000 && $7 !~ /nologin/ {print $1, $7}' /etc/passwd
admin /bin/bash
deploy /bin/bash
host$ awk '$9 ~ /^5/ {n[$7]++} END {for (p in n) print n[p], p}' /var/log/nginx/access.log | sort -rn | head -3
412 /api/report
37 /api/login
host$ awk '{bytes += $10} END {printf "%.1f MiB\n", bytes/1048576}' /var/log/nginx/access.log
host$ df -P | awk 'NR > 1 && $5+0 >= 85 {print $6, $5}'
/var 91%
host$ ss -tan | awk 'NR > 1 {s[$1]++} END {for (k in s) print k, s[k]}'
host$ journalctl -u nginx --since today -o cat | grep -c "upstream timed out"
Reading the examples
The access-log pipeline counts 5xx responses per path and shows the worst ones, using only the fields of the log format. The df -P example uses $5+0 to turn "91%" into a number. That's a common awk idiom for values with units.
Documented example, not captured output.
How it works at runtime
Text Processing is part of Text Processing. Text Processing covers Linux command-line pipelines that read byte/text streams, select or transform records/fields, compare outputs and feed results into later commands without confusing display success with semantic correctness.
Runtime state ownership and mechanics. Shell behavior is a parsing and process-construction pipeline: lexical parsing, quoting, expansions, redirections, pipeline setup, command resolution, fork/exec or builtin execution, wait/status collection and signal/job-control handling. Text-processing tools operate on byte or character streams with locale-dependent behavior, and regular expressions differ by tool and mode. A visible command line can therefore differ materially from the argv, file descriptors and environment presented to the executed program.
Topic-specific state model. Text Processing covers Linux command-line pipelines that read byte/text streams, select or transform records/fields, compare outputs and feed results into later commands without confusing display success with semantic correctness.
Technical metadata. Host/distribution/kernel, Bash/shell version and invocation mode, login/interactive state, cwd/mount namespace, uid/gid, locale/IFS, shell options, startup files, variable/environment state, source command/script, quoting/expansion, final argv, fd 0/1/2 and redirections, pipeline stages/PIPESTATUS, path/inode/object metadata, exit status/signal, target read-back, original workload result.
Interpretation rule. - Text output ≠ structured data unless delimiters, escaping and encoding are explicitly defined.
- A pipeline exit status ≠ every stage succeeded unless shell options or explicit status inspection preserve upstream failures.
- grep/sed/awk patterns ≠ interchangeable regex dialects or semantics.
- Human-readable command output ≠ stable machine interface across versions/locales.
Quick reference
Text processing toolkit:
| Tool | Use |
|---|---|
grep -E, rg | Find lines |
sed | Stream editing, substitutions |
awk | Fields, calculations, reports |
cut, paste, tr | Columns, characters |
sort, uniq -c | Ordering, counting |
jq, yq | JSON/YAML |
column -t | Align output |
awk '$9 >= 500 {print $7}' access.log | sort | uniq -c | sort -rn | head
sed -i.bak 's/^#\?PermitRootLogin.*/PermitRootLogin no/' /etc/ssh/sshd_config
journalctl -o json -n 100 | jq -r '._COMM' | sort | uniq -c
Limits and how it fails
Primary failure point. Text-processing evidence requires showing that the final stream has the expected records/fields/content under the actual locale/encoding and that upstream stage failures cannot be silently accepted.
Model. A command shown in history is not necessarily what the program received after expansion. Pipeline exit status can represent only one command unless shell options change that behavior. Quoting errors, locale differences and glob expansion can look like tool defects. Builtins and external commands can share names. Successful script exit does not show every intended side effect occurred unless the script checks them. Keep shell semantics separate from the subsystem operated on by the command.
ReferenceConfiguration & state1 section · depth on demand
Configuration, persistence and lifecycle
Configuration intent and lifecycle. Separate shell startup configuration from script code and from the external tools a script invokes. Login versus interactive startup files, set options, aliases/functions, locale, PATH and environment inheritance all affect behavior. Scripts should make interpreter, error handling, quoting and input assumptions explicit. Prefer portable constructs only when portability is a requirement; otherwise record the required shell/tool version. Do not assume an interactive alias, function or profile exists in cron, systemd or automation contexts.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Text Processing. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://www.gnu.org/software/coreutils/manual/coreutils.html · confidence 94%What changed and what may be affected
Recent technical edits are separated from ordinary page timestamps. Relationship impact is advisory: it identifies nearby canonical references to review, not automatic breakage.
Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.
Quick lookup tables
Text Processing operational reference
Topic-specific lookup boundaries, proof limits and next-step Evidence for Text Processing.
| Lookup boundary | Topic-specific reference | Operational use |
|---|---|---|
| Scope / effective state | Text Processing covers Linux command-line pipelines that read byte/text streams, select or transform records/fields, compare outputs and feed results into later commands without confusing display success with semantic correctness. | Establish exactly what this Topic owns before crossing into another subsystem. |
| Fast verification | Pin host/distribution + shell/version/mode → identify cwd/mount namespace + input/path/stream → preserve quoting/expansion and final argv → map fd/pipeline/process boundaries → inspect object/variable/status/signal state → make one minimal reversible change → read back effective state → repeat original consumer/script/workload test. | Use the shortest evidence path first; a fast check is a boundary test, not blanket proof. |
| Verification chain | raw input/source → bytes/encoding + record delimiters → shell quoting/expansion → filter/parser/transform stage(s) → stdout/stderr + exit status per stage → final text/data contract → downstream consumer/decision | Trace requested/configured state through effective state to the observed workload result. |
| Failure boundary | Text-processing proof requires showing that the final stream has the expected records/fields/content under the actual locale/encoding and that upstream stage failures cannot be silently accepted. | Stop broad troubleshooting at the first boundary that is not supported by evidence. |
| Positive evidence | Correlated Linux file/text/shell evidence can establish this proof path: raw input/source → bytes/encoding + record delimiters → shell quoting/expansion → filter/parser/transform stage(s) → stdout/stderr + exit status per stage → final text/data contract → downstream consumer/decision | Use this observation only for the specific claim it actually supports. |
| Evidence limit | It does not independently prove behavior outside the captured host, shell/session, cwd/namespace, input, process, filesystem, locale, time or workload scope. Text-processing proof requires showing that the final stream has the expected records/fields/content under the actual locale/encoding and that upstream stage failures cannot be silently accepted. | Do not promote a local success signal into end-to-end or adjacent-dependency proof. |
| Next troubleshooting check | Continue from the first unproven boundary: capture the exact shell-delivered argv/streams or resolved object, verify the effective target state, change only the demonstrated cause, then repeat the original consumer/script/workload and adjacent regression checks. | Continue to the next unresolved boundary while preserving the original test condition. |
Text Processing · operational reference
Compact Linux state, persistence, verification and boundary reference for fast lookup.
| Reference boundary | Text Processing |
|---|---|
| Topic path | Text Processing |
| Runtime state | Text Processing covers Linux command-line pipelines that read byte/text streams, select or transform records/fields, compare outputs and feed results into later commands without confusing display success with semantic correctness. |
| Fast checks | - Capture a representative raw input sample including edge cases, delimiters, whitespace, empty fields and non-ASCII/binary cases. - Run each selection/transformation stage separately and compare record counts and sample outputs before composing the pipeline. - Pin locale/encoding and quote patterns/arguments so the shell does not transform them before the text-processing tool receives them. - Verify the final output against an expected oracle before passing it to a mutating command or automated decision. |
| Verification chain | raw input/source → bytes/encoding + record delimiters → shell quoting/expansion → filter/parser/transform stage(s) → stdout/stderr + exit status per stage → final text/data contract → downstream consumer/decision Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return/regression → explicit Evidence boundary. Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return path or regression → explicit Evidence boundary. |
| Failure boundary | Text-processing proof requires showing that the final stream has the expected records/fields/content under the actual locale/encoding and that upstream stage failures cannot be silently accepted. Boundary chain: process/context → userspace configuration → kernel subsystem/resource → device/network/filesystem dependency → effective state → original workload. |
| Persistence rule | Prove which configuration source owns the state, then prove that the running consumer loaded or generated the intended state. |