I'm trying to extract specific lines from the output of a command that outputs a lot of lines of text. I've hit a bit of a wall at this point:
pathsText=$(system_profiler SPApplicationsDataType | egrep '^\s+Location:\s+.*$')
This extracts the correct lines, but it puts them all into a single long line, with matches separated by spaces rather than newlines.
In other words, I'm expecting something like this:
Location: /a/b
Location: /c/d/e
...
And that's what I get if I run that same egrep command against a text file containing the output of system_profiler SPApplicationsDataType in the Terminal. But the command above does not put that into pathsText. Instead, it's giving me:
Location: /a/b Location: /c/d/e ...
Unfortunately, I can't just split based on spaces, because the paths contained in each line may contain spaces.
What am I doing wrong?