Simple bash regex example

Since versions 3 bash has included a simple regular expression operation =~

Below is a simple example of it in action

######### example code #########
#search for a process and print specific section
ps=`ps aux | grep stuff | awk '{print $12 "_" $13}' `

#do some stuff
if [[ $ps =~ "something im looking for" ]]; then
    #do what you want
fi
##############################

Justin Kelly

Justin Kelly

Web Developer, Business Analytics, Data Engineer specialising in PHP and Tableau

Based in Melbourne, Australia

Feel free to contact me justin@kelly.org.au or _justin_kelly

Leave a comment

Name Notify me of replies by email.