File Content
Commands for reading file content, counting statistics, transforming text, and splitting files into pieces.
Concatenate files and print on the standard output. Returns CatLine objects with LineNumber, Content, and FileName properties.
Syntax
Section titled “Syntax”cat [OPTIONS] [FILE...]| Flag | Description |
|---|---|
-n | Number all output lines |
-b | Number non-blank output lines (overrides -n) |
-s | Squeeze consecutive blank lines into one |
-E | Display $ at the end of each line |
-T | Display ^I for tab characters |
Return type
Section titled “Return type”PsBash.CatLine with properties:
| Property | Type | Description |
|---|---|---|
LineNumber | int | Line number in the file |
Content | string | Raw line content |
FileName | string | Source file path (empty for pipeline input) |
BashText | string | Formatted output including line numbers and transformations |
Examples
Section titled “Examples”# Display file contentscat README.md# Number all linescat -n script.ps1 1 #!/usr/bin/env pwsh 2 Import-Module PsBash 3 4 ls -la | grep '.log'# Number only non-blank lines and show line endingscat -b -E notes.txt# Squeeze blank lines and show tabscat -s -T Makefile# Access typed properties$lines = cat src/PsBash.psm1$lines[0].Content # raw text of line 1$lines.Count # total line count$lines | Where-Object { $_.Content -match 'function' }# Concatenate multiple filescat header.txt body.txt footer.txtOutput the first part of files. In pipeline mode, head is a pipeline bridge: it passes through the original typed objects unchanged.
Syntax
Section titled “Syntax”head [-n COUNT] [FILE...]| Flag | Description |
|---|---|
-n | Number of lines to output (default: 10) |
Return type
Section titled “Return type”- File mode:
PsBash.CatLineobjects - Pipeline mode: passes through whatever type it receives
Examples
Section titled “Examples”# First 10 lines of a file (default)head README.md# First 3 lineshead -n 3 README.md# Pipeline bridge -- returns LsEntry objects, not strings$top5 = ls -la | sort -k5 -rn | head -n 5$top5[0].SizeBytes # real integer$top5[0].Name # real string# Pipeline bridge -- returns PsEntry objects$procs = ps aux | sort -k3 -rn | head 5$procs[0].CPU # real double$procs[0].Command # real stringOutput the last part of files. Like head, tail is a pipeline bridge that preserves original object types.
Syntax
Section titled “Syntax”tail [-n COUNT] [FILE...]| Flag | Description |
|---|---|
-n | Number of lines to output (default: 10). Prefix with + to start from line N. |
Return type
Section titled “Return type”- File mode:
PsBash.CatLineobjects - Pipeline mode: passes through whatever type it receives
Examples
Section titled “Examples”# Last 10 lines of a file (default)tail server.log# Last 5 linestail -n 5 server.log# From line 3 onward (skip first 2 lines)tail -n +3 data.csv# Pipeline bridge -- returns LsEntry objects$smallest = ls -la | sort -k5 -n | tail -n 3$smallest[0].SizeBytes # real integerConcatenate and print files in reverse line order. Returns TextOutput objects.
Syntax
Section titled “Syntax”tac [-s SEPARATOR] [FILE...]| Flag | Description |
|---|---|
-s | Use SEPARATOR instead of newline as the record separator |
Return type
Section titled “Return type”PsBash.TextOutput with a BashText property.
Examples
Section titled “Examples”# Reverse lines of a filetac changelog.txt# Reverse pipeline inputcat data.txt | tac# Custom separatortac -s '---' sections.txtPrint newline, word, and byte counts. Returns WcResult objects with typed integer properties.
Syntax
Section titled “Syntax”wc [OPTIONS] [FILE...]| Flag | Description |
|---|---|
-l | Print only the line count |
-w | Print only the word count |
-c | Print only the byte count |
When no flags are given, all three counts are printed.
Return type
Section titled “Return type”PsBash.WcResult with properties:
| Property | Type | Description |
|---|---|---|
Lines | int | Number of newlines |
Words | int | Number of whitespace-delimited words |
Bytes | int | Number of bytes |
FileName | string | Source file path |
BashText | string | Formatted count output |
Examples
Section titled “Examples”# Full counts for a filewc README.md 42 187 1084 README.md# Line count onlywc -l src/PsBash.psm1# Count lines from pipelinecat README.md | grep 'bash' | wc -l# Multiple files produce a total rowwc -l src/*.ps1# Access typed properties$stats = wc README.md$stats.Lines # 42$stats.Words # 187$stats.Bytes # 1084Number lines of files. By default, blank lines are not numbered.
Syntax
Section titled “Syntax”nl [-ba] [FILE...]| Flag | Description |
|---|---|
-ba | Number all lines, including blank lines |
Without -ba, blank lines are passed through without a number.
Return type
Section titled “Return type”PsBash.TextOutput with a BashText property.
Examples
Section titled “Examples”# Number non-blank linesnl script.ps1 1 Import-Module PsBash 2 $files = ls -la
3 echo "Found $($files.Count) files"# Number all lines including blanksnl -ba script.ps1 1 Import-Module PsBash 2 $files = ls -la 3 4 echo "Found $($files.Count) files"# Number pipeline inputcat README.md | nlReverse characters of each line. Returns TextOutput objects.
Syntax
Section titled “Syntax”rev [FILE...]Return type
Section titled “Return type”PsBash.TextOutput with a BashText property.
Examples
Section titled “Examples”# Reverse characters in a filerev names.txt# Reverse pipeline inputecho "hello world" | revdlrow olleh# Reverse multiple filesrev file1.txt file2.txtstrings
Section titled “strings”Print sequences of printable characters (ASCII 0x20-0x7E) found in files. Useful for extracting readable text from binary data.
Syntax
Section titled “Syntax”strings [-n LENGTH] [FILE...]| Flag | Description |
|---|---|
-n | Minimum string length (default: 4) |
Return type
Section titled “Return type”PsBash.TextOutput with a BashText property.
Examples
Section titled “Examples”# Extract printable strings from a binarystrings program.exe# Only strings of 8+ charactersstrings -n 8 program.exe# Extract from pipeline inputcat binary.dat | strings -n 6Wrap each input line to fit in a specified width.
Syntax
Section titled “Syntax”fold [-w WIDTH] [-s] [-b] [FILE...]| Flag | Description |
|---|---|
-w | Maximum line width (default: 80) |
-s | Break at spaces instead of mid-word |
-b | Count bytes rather than columns (default for ASCII) |
Return type
Section titled “Return type”PsBash.TextOutput with a BashText property.
Examples
Section titled “Examples”# Wrap at 40 columnsfold -w 40 essay.txt# Wrap at spaces to avoid breaking wordsfold -w 60 -s paragraph.txt# Wrap pipeline inputcat README.md | fold -w 72 -sexpand
Section titled “expand”Convert tab characters to spaces.
Syntax
Section titled “Syntax”expand [-t TABWIDTH] [FILE...]| Flag | Description |
|---|---|
-t | Tab stop width (default: 8) |
Return type
Section titled “Return type”PsBash.TextOutput with a BashText property.
Examples
Section titled “Examples”# Convert tabs to 8 spaces (default)expand Makefile# Convert tabs to 4 spacesexpand -t 4 src/main.go# Expand pipeline inputcat config.yaml | expand -t 2unexpand
Section titled “unexpand”Convert spaces to tabs.
Syntax
Section titled “Syntax”unexpand [-t TABWIDTH] [-a] [FILE...]| Flag | Description |
|---|---|
-t | Tab stop width (default: 8) |
-a | Convert all sequences of spaces, not just leading spaces |
Without -a, only leading spaces are converted.
Return type
Section titled “Return type”PsBash.TextOutput with a BashText property.
Examples
Section titled “Examples”# Convert leading spaces to tabs (default: 8-wide)unexpand source.py# Convert leading spaces to 4-wide tabsunexpand -t 4 source.py# Convert all space runs, not just leadingunexpand -a -t 4 data.txtSplit a file into pieces. Output files are written to the current directory.
Syntax
Section titled “Syntax”split [-l LINES] [-d] [-a LENGTH] [FILE [PREFIX]]| Flag | Description |
|---|---|
-l | Number of lines per output file (default: 1000) |
-d | Use numeric suffixes (00, 01, …) instead of alphabetic (aa, ab, …) |
-a | Suffix length (default: 2) |
The default output prefix is x, producing files xaa, xab, xac, … (or x00, x01, x02, … with -d).
Return type
Section titled “Return type”No output objects. Files are written to disk.
Examples
Section titled “Examples”# Split into 1000-line chunks (default)split largefile.csv# produces: xaa, xab, xac, ...# Split into 100-line chunks with numeric suffixessplit -l 100 -d data.csv# produces: x00, x01, x02, ...# Custom prefixsplit -l 50 data.csv chunk_# produces: chunk_aa, chunk_ab, chunk_ac, ...# Longer suffixes for large filessplit -l 10 -d -a 4 huge.log part_# produces: part_0000, part_0001, part_0002, ...# Split from pipelinecat data.csv | split -l 500 - output_Pipeline bridge pattern
Section titled “Pipeline bridge pattern”head and tail are pipeline bridges. They do not create new objects. They pass through the exact objects they receive, preserving type information across the entire pipeline.
# CatLine objects survive through head$lines = cat file.txt | head -5$lines[0].PSObject.TypeNames[0] # PsBash.CatLine$lines[0].Content # raw text
# LsEntry objects survive through tail$files = ls -la | tail -3$files[0].PSObject.TypeNames[0] # PsBash.LsEntry$files[0].SizeBytes # real integer
# PsEntry objects survive through head$procs = ps aux | sort -k3 -rn | head 5$procs[0].PSObject.TypeNames[0] # PsBash.PsEntry$procs[0].CPU # real doubleThis means you can chain bridge commands freely and still access typed properties at the end of the pipeline.