Working with Text Files | wc, sort, uniq & cut | Mac/Linux Terminal

13views
00
4:46
T
Taught by Celeste AI - AI Coding Coach
View on YouTube
Description
Master essential text processing commands in Mac and Linux terminals! In this comprehensive tutorial, you'll learn how to count words, lines, and characters with `wc`, organize text data with `sort`, find unique lines with `uniq`, and extract columns with `cut`. šŸ“Š **Word Count with wc** - `wc` command to count words, lines, and characters in files - `wc -l` to count only lines (perfect for counting file entries) - `wc -w` to count only words (sequences separated by whitespace) - `wc -c` to count only characters (including spaces and newlines) - `wc -m` to count multibyte characters correctly - Using `wc` with piped input (e.g., `ls | wc -l` to count files) - Understanding default output: line count, word count, character count, filename - Practical examples for analyzing text files and understanding file structure šŸ”„ **Sorting and Finding Unique Lines** - `sort` command to organize lines alphabetically or numerically - `sort -n` for numerical sorting (treats numbers as numbers) - `sort -r` to reverse sort order (descending) - Using `sort` with files or standard input (perfect for pipelines) - `uniq` command to find and display unique lines in sorted text - `uniq -c` to count occurrences of each unique line - `uniq -d` to show only duplicate lines - `uniq -u` to show only unique lines that appear once - Combining `sort` and `uniq` for powerful text analysis - Finding duplicates and organizing information efficiently āœ‚ļø **Extracting Columns with cut** - `cut` command to extract specific columns or fields from text files - `cut -d:` to specify delimiter (colon-separated files like `/etc/passwd`) - `cut -f1` to extract the first field - `cut -f1,3` to extract multiple fields (comma-separated) - `cut -f1-3` to extract a range of fields - Working with tab-separated files (tab is default delimiter) - `cut -c1-10` to extract specific characters by position - Extracting columns from CSV and structured text data - Practical examples for data extraction and analysis **Commands Covered:** - `wc` - Word, line, and character count - `wc -l` - Count lines only - `wc -w` - Count words only - `wc -c` - Count characters only - `wc -m` - Count multibyte characters - `sort` - Sort lines alphabetically - `sort -n` - Sort numerically - `sort -r` - Reverse sort order - `uniq` - Find unique lines - `uniq -c` - Count unique line occurrences - `uniq -d` - Show only duplicates - `uniq -u` - Show only unique lines - `cut -d:` - Extract fields with delimiter - `cut -f1` - Extract first field - `cut -f1,3` - Extract multiple fields - `cut -f1-3` - Extract field range - `cut -c1-10` - Extract characters by position **Perfect for:** - Mac and Linux terminal beginners - Anyone learning text processing - Data analysts working with text files - Developers processing logs and data - System administrators analyzing system files - Users working with structured text data **Why This Matters:** Text processing commands are fundamental tools for working with data in Unix-like systems. Mastering `wc`, `sort`, `uniq`, and `cut` gives you powerful capabilities for: - Analyzing file contents and structure - Processing and organizing text data - Finding patterns and duplicates - Extracting specific information from files - Data analysis and log processing - Working with structured text formats **Real-World Applications:** - Counting lines in log files to track activity - Analyzing word counts in documents - Sorting and organizing data files - Finding duplicate entries in lists - Extracting usernames from system files - Processing CSV and delimited data files - Analyzing text file statistics - Filtering and organizing command output - Extracting specific columns from structured data - Processing and cleaning text data **Common Text Processing Patterns:** - `wc -l file.txt` - Count lines in a file - `ls | wc -l` - Count files in a directory - `sort file.txt` - Sort lines alphabetically - `sort -n numbers.txt` - Sort numbers numerically - `sort file.txt | uniq` - Sort and find unique lines - `sort file.txt | uniq -c` - Count unique line occurrences - `cut -d: -f1 /etc/passwd` - Extract usernames - `cut -f1,3 data.csv` - Extract first and third columns - `cut -c1-10 file.txt` - Extract first 10 characters **Pipeline Power:** - Combine commands for powerful text processing - `cat file.txt | sort | uniq -c` - Sort and count unique lines - `ls -l | wc -l` - Count files in directory - `cut -d: -f1 file.txt | sort | uniq` - Extract, sort, and find unique values - Chain multiple commands for complex data processing - Process large files efficiently with pipelines **Key Concepts:** - `wc` provides quick statistics about text files - `sort` requires understanding of alphabetical vs. numerical sorting - `uniq` only works correctly on sorted input - `cut` is perfect for structured, delimiter-separated files - Combining commands in pipelines multiplies their power
Back to tutorials

Duration

4:46

Published

December 27, 2025

Added to Codegiz

March 15, 2026

Open in YouTube