Text Processing

CommandDescription
cat fileDisplay file with line numbers
head [-n N] fileShow first N lines (default 10)
tail [-n N] fileShow last N lines (default 10)
grep [flags] pattern [files]Search files for pattern
sort [-r/-n/-u] fileSort lines
uniq [-c/-d] fileRemove consecutive duplicate lines
wc [-l/-w/-c] fileCount lines, words, or characters
diff file1 file2Compare two files
tr [-d] s1 s2 fileTranslate or delete characters
cut -d/-f/-c fileExtract fields or characters
rev fileReverse characters in each line
tac filePrint file with lines in reverse order
paste [-d] file fileMerge lines from multiple files
more/lessPaginated 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:3

Flags: -i case insensitive, -n line numbers, -r recursive, -c count only.

sort

Shell
> sort -r names.txt
Zara
Mike
Alice