Reputation: 75
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?
Upvotes: 2
Views: 644
Reputation: 9877
You could use cut
as well:
your_script | cut -d = -f 2-
(where your_script
does something equivalent to echo INFOPLIST_FILE = MajorDomo/MajorDomo-Info.plist
)
If you need to trim the space at the beginning:
your_script | cut -d = -f 2- | cut -d ' ' -f 2-
If you have multiple spaces at the beginning and you want to trim them all, you'll have to fall back to sed: your_script | cut -d = -f 2- | sed 's/^ *//'
(or, simpler, your_script | sed 's/^[^=]*= *//'
)
Upvotes: 3
Reputation: 23384
Bash
IFS=' =' read -r _ x <<<"INFOPLIST_FILE = MajorDomo/MajorDomo-Info.plist"
printf "%s\n" "$x"
MajorDomo/MajorDomo-Info.plist
Upvotes: 0
Reputation: 9877
Assuming your script outputs a single line, there is a shell only solution:
line="$(your_script)"
echo "${line#*= }"
Upvotes: 2
Reputation: 785971
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
Upvotes: 3
Reputation: 46435
Not exactly what you were asking, but
echo "INFOPLIST_FILE = MajorDomo/MajorDomo-Info.plist" | sed 's/.*= \(.*\)$/\1/'
will do what you want.
Upvotes: 3