I have tried many many times with different tools to extract a pattern from a file using unix tools, but I can't seem to get them to do what I want. So I have a file like this:
[blah]
project=abc123
ON#IRUjdi2ujnq!De
And I want to capture the project name.
I've tried using grep, egrep, awk, and sed, but I haven't been able to get them to work. Here's my current attempt.
cat file | sed -n "s/project = \(.*\)/\1/p"
and here's the current output
abc123
ON#IRUjdi2ujnq!De
For some reason it's considering the last 2 lines to match. I thought my regex would require a literal match on project =
but it seems this is not the case.
Can some unix wizard help me out here? Any standard unix tool is fine.
------ EDIT ------
So actually my problem was slightly different. I was actually doing
gcloud config list project | sed -n "s/project = \(.*\)/\1/p"
Sorry I thought that it wouldn't make a difference, but apparently this is the issue.
If you do this gcloud config list project >> file
It will actually only output the the listing of your projects to the file and then it will print
Your active configuration is: [default]
to the terminal, and this is what was messing things up. If I manually write the whole output of doing the gcloud command to a file and then ran sed on that it actually worked. So it's something strange about how gcloud is outputting it's data.