Index

Text Manipulation

Translate or delete characters

replace all occurrences of a colon with a newline character (split path)
echo $PATH | tr ':' '\n'
to upper case
tr "[a-f]" "[A-F]"
delete all occurrences of a single character
ls / | tr -d "t"
delete a range of characters
ls / | tr -d "[aeoui]"
ls / | tr -d "[a-d]"
extracting characters by index
echo "earth" | cut -c 2-4
deleting characters by index
echo "earth" | cut -c 2-4 --complement
add line numbers
echo -e "a\nb" | nl
h2 contains
contains() {
	for word in $(echo "$1")
	do
		if [ "$word" = "$2" ]; then
			echo "found $2!"
			return 0
		fi
	done
	echo "not found $2!"
	return 1
}

Sorting

sort file contents
sort [file]
reverse sort
sort -r [file]
remove duplicate lines
sort -u [file]

arithmetic

basic arithmetic
echo "2 * 5 + 4" | bc
expr 2 + 4

Counting lines / words

count words in file (newlines, words, characters)
wc [file]
count newlines only
wc -l [file]
determining the length of a string
len=$(expr length "$1")
len=$(echo -n "$str" | wc -c)

Column Layout

align column based output
mount | column -t

date / time

unix timestamp
date +%s
date yyyy-mm-dd hh:mm:ss
date "+%Y-%m-%d %H:%M:%S"
date UTC yyyy-mm-dd hh:mm:ss
date -utc "+%Y-%m-%d %H:%M:%S"