Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grep in bash with regex

I am getting the following output from a bash script:

INFOPLIST_FILE = MajorDomo/MajorDomo-Info.plist

and I would like to get only the path(MajorDomo/MajorDomo-Info.plist) using grep. In other words, everything after the equals sign. Any ideas of how to do this?

like image 523
Alan Ihre Avatar asked Dec 13 '25 23:12

Alan Ihre


2 Answers

This job suites more to awk:

s='INFOPLIST_FILE = MajorDomo/MajorDomo-Info.plist'
awk -F' *= *' '{print $2}' <<< "$s"
MajorDomo/MajorDomo-Info.plist

If you really want grep then use grep -P:

grep -oP ' = \K.+' <<< "$s"
MajorDomo/MajorDomo-Info.plist
like image 170
anubhava Avatar answered Dec 15 '25 19:12

anubhava


Not exactly what you were asking, but

echo "INFOPLIST_FILE = MajorDomo/MajorDomo-Info.plist" | sed 's/.*= \(.*\)$/\1/'

will do what you want.

like image 39
Floris Avatar answered Dec 15 '25 18:12

Floris