myhelp:bash
Table of Contents
Read a file per line
# while read line; do echo "$line"; done < file.txt
Upper to Lower
Is pretty easy done
# cat /path/to/file.txt|tr '[:upper:]' '[:lower:]'
or
# echo "LadiDA"|tr '[:upper:]' '[:lower:]'
SED Examples
Delete a line with a string in it. For example old ssh-keys:
# sed -i "/myuser@old.laptop/d" .ssh/authorized_keys
Calculate
You can use the expr
# expr 1 + 2
and you will get 3 as result.
Also some more fancy stuff is possible. For example in a for-loop:
for i in {1..9}; do echo "10.20.30.$(expr $i + 40) servername-$i"; done
Bash redirection
stdout to file
# command > file.txt
stderr to file
# command 2> /dev/null
stdout AND stderr to file
# command &> file.txt
stdout to file AND stderr to file
# command > file.txt 2> /dev/null
stdout to stderr
# command 1>&2
stderr to stdout
# command 2>&1
myhelp/bash.txt · Last modified: by ulrich
