Text Processing
| Command | Description |
|---|---|
cat file | Display file with line numbers |
head [-n N] file | Show first N lines (default 10) |
tail [-n N] file | Show last N lines (default 10) |
grep [flags] pattern [files] | Search files for pattern |
sort [-r/-n/-u] file | Sort lines |
uniq [-c/-d] file | Remove consecutive duplicate lines |
wc [-l/-w/-c] file | Count lines, words, or characters |
diff file1 file2 | Compare two files |
tr [-d] s1 s2 file | Translate or delete characters |
cut -d/-f/-c file | Extract fields or characters |
rev file | Reverse characters in each line |
tac file | Print file with lines in reverse order |
paste [-d] file file | Merge lines from multiple files |
more/less | Paginated output viewer |
grep
Search for patterns in files with highlighted matches. Supports recursive search, case-insensitive matching, line numbers, and match counting.
Shell
> grep -rn "TODO" src/
src/Parser.cs:42: // TODO: Handle forward references
src/Interpreter.cs:156: // TODO: Optimize stack layout
> grep -ic "error" logs/
logs/app.log:15
logs/server.log:3Flags: -i case insensitive, -n line numbers, -r recursive, -c count only.
sort
Shell
> sort -r names.txt
Zara
Mike
Alice