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")
		if [ "$word" = "$2" ]; then
			echo "found $2!"
			return 0
	echo "not found $2!"
	return 1


expr "abc" : '[a-c]\+$'


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

Counting lines / words

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

Column Layout

select whitespace separated column [n]
awk '{print $[n]}'
select column [n] from output with delimiter [d]
cut -d [d] -f [n]
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 -u "+%Y-%m-%d %H:%M:%S"
date --utc "+%Y-%m-%d %H:%M:%S"
date day of week short
date +%a