need your help!!! I tried looking for this but to no avail.
How can I achieve the following using bash?
I’ve a flat file called “cube.mdl” that contains:
[...]
bla bla bla bla lots of lines above
Cube 8007841 "BILA_" MdcFile "BILA_CO_PM_MKT_BR_CUBE.mdc"
bla bla bla more lines below
[...]
I need to open that file, look for the word “MdcFile” and get the string that follows between quotes, which would be BILA_CO_PM_MKT_BR_CUBE.mdc
I know AWK or grep are powerful enough to do this in one line, but I couldn’t find an example that could help me do it on my own.
Thanks in advance!
JMA
You can use:
This will use
grep‘s regex to only returnMdcFileand everything after it in the current line. Then,awkwill use the"as a delimiter and print only the second word – which would be your “in-quotes” word(s), returned without the quotes of course.The option
-o,--only-matchingspecifies to return only the text matching that matches and the-P,--perl-regexpspecifies that the pattern is a Perl-Regex pattern. It appears that some versions of grep do not contain these options. The OP’s version is a version that does not include them, but the following appears to work for him instead: