Advanced Text Processing | sed, awk & tr | Mac/Linux Terminal
17views
1likes
05:49
T
Taught by Celeste AI - AI Coding Coach
View on YouTubeDescription
Master advanced text processing commands in Mac and Linux terminals! In this comprehensive tutorial, you'll learn powerful text manipulation tools: stream editing with `sed`, pattern scanning with `awk`, and character translation with `tr`.
š **Stream Editing with sed**
- `sed` command for performing text transformations on files or piped input
- `sed 's/old/new/g'` for find and replace operations (global substitution)
- `sed 's/old/new/'` for replacing only the first occurrence on each line
- Using `sed` with files or piped input from other commands
- `sed -i` to edit files in place (modifies file directly)
- `sed -n` with `p` to print only matching lines
- `sed '/pattern/d'` to delete lines matching a pattern
- Regular expression support for pattern matching
- Practical examples for batch text replacement and automated processing
š **Pattern Scanning with awk**
- `awk` command for pattern scanning and data processing
- `awk '{print $1}'` to print the first field of each line
- Accessing fields with `$1`, `$2`, `$3`, etc. (`$0` for entire line)
- `awk -F:` to specify field separator (colon, comma, etc.)
- Performing calculations and comparisons with `awk`
- Built-in variables: `NF` (number of fields), `NR` (record number), `FS` (field separator)
- Filtering lines based on conditions (e.g., `awk '$2 80'`)
- Formatting output and creating reports
- Processing structured data like CSV files and system files
š¤ **Character Translation with tr**
- `tr` command for translating, squeezing, or deleting characters
- `tr 'a-z' 'A-Z'` to convert lowercase to uppercase
- `tr 'A-Z' 'a-z'` to convert uppercase to lowercase
- `tr -d '0-9'` to delete digits from text
- `tr -s ' '` to squeeze repeated spaces into single space
- `tr ' ' '\n'` to convert spaces to newlines
- Character classes: `[:lower:]`, `[:upper:]`, `[:digit:]`, `[:alnum:]`, `[:alpha:]`
- Working with character sets and ranges
- Perfect for cleaning text data and character-level manipulation
**Commands Covered:**
- `sed 's/old/new/g'` - Global substitution
- `sed 's/old/new/'` - First occurrence substitution
- `sed -i` - Edit file in place
- `sed -n 'p'` - Print matching lines
- `sed '/pattern/d'` - Delete matching lines
- `awk '{print $1}'` - Print first field
- `awk '{print $1, $3}'` - Print multiple fields
- `awk -F: '{print $1}'` - Use colon as delimiter
- `awk '$2 80'` - Filter by condition
- `awk '{print NR, $0}'` - Print line numbers
- `tr 'a-z' 'A-Z'` - Convert to uppercase
- `tr -d '0-9'` - Delete digits
- `tr -s ' '` - Squeeze spaces
- `tr ' ' '\n'` - Convert spaces to newlines
**Perfect for:**
Back to tutorialsOpen in YouTube
Duration
5:49
Published
December 27, 2025
Added to Codegiz
March 15, 2026