cut and tr
cut — Extract columns
cut -d: -f1 /etc/passwd # Field 1, delimiter :
cut -d: -f1,3 /etc/passwd # Fields 1 and 3
cut -d, -f2 data.csv # CSV second column
cut -c1-10 file.txt # Characters 1-10
cut -c5- file.txt # From character 5 to end
tr — Translate characters
echo 'hello' | tr 'a-z' 'A-Z' # Lowercase to uppercase
echo 'Hello World' | tr ' ' '_' # Replace spaces with _
echo 'hello' | tr -d 'l' # Delete all 'l' chars
cat file.txt | tr -s ' ' # Squeeze multiple spaces
Practical examples
# Extract all usernames from /etc/passwd
cut -d: -f1 /etc/passwd
# Get list of user shells
cut -d: -f7 /etc/passwd | sort | uniq -c
# Convert CSV column to uppercase
cut -d, -f1 data.csv | tr 'a-z' 'A-Z'