I feel like this is a really easy question, and when I Google, I find lots of answers for part of the problem, but when I try to put them together, it doesn't work and I can't figure out why.
Here's the scenario:
- I have a file with a lot of text in it.
- One of those lines matches this pattern:
foo = 1700;
- I want to extract
- I want to save it into a bash script variable so I can refer to it later in the script.
I cannot get past step 3. Here's what I've tried:
sed -nE 's/^foo = //p' file | sed -nE 's/;//p'
This prints out:
Great, but what if I need to trim white space or something? If I can't use
+, I wouldn't know how to do that. I learned that you can't use
+ in a substitution on another answer, so I can't figure out how to do this. I looked into the man page of grep, and I didn't see any option for groups when I search for that word. I think I know how to solve this in awk, but I've always found its regex functions to be a little clunky and for the commandline scripts to require too many escapes, so ideally that's not the only way to solve this.