grep – Useful expressions

Grep file-size from du -sh
Format (10K , 10.1M , 1000.21G)
grep -oE "^[[:digit:]]+(\.[[:digit:]]+)?[KMG]"
Or
grep -oE "^[[:digit:]]+(\.[[:digit:]]+)?[KMG]|^[[:digit:]]+[[:blank:]]"
Grep IP address
grep -E ‘(^|[[:blank:]])[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}([[:blank:]]|$)’ | sed -e ‘s/[[:blank:]]//g’
# grep sed awk
grep -E ‘(^|[[:blank:]])[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}([[:blank:]]|$)’ | sed -e ‘s/[[:blank:]]//g’ | awk -F"." ‘{ if ($1 <= 255 && $2 <= 255 && $3 <= 255 && $4 <= 255) print $1"."$2"."$3"."$4}’
Grep upper or lower character
# grep any upper character and lower ‘a’
grep -E ‘[[:upper:]a]’
# grep upper of lower single alphabet (defined by variable)
(alpha=a;Alpha=`echo ${alpha} | tr [a-z] [A-Z]` ; echo aABab | grep -E ‘[${alpha}${Alpha}]’)

awk (1) cryptsetup (1) dd (2) device (1) drive (1) encryption (2) ext (1) filesystem (1) firefox (1) grep (1) loop-back (1) losetup (1) mkfs (1) mount (1) protocol-handler (1) security (2) sed (1) ssh (3) stat (1) truncate (1) urandom (1)

Leave a comment

Your email address will not be published. Required fields are marked *