This is a sed and RegEx beginner question, but I was not able to answer it myself through googling.
Szenario
I have got a plain text file like this as the log file of a command:
Checking version of 'make' >= 379... succeeded. (382)
Checking version of 'm4' >= 104... succeeded. (104)
Checking version of 'pkg-config' >= 15... succeeded. (25)
Checking version of 'autoreconf' >= 258... succeeded. (268)
Checking version of 'automake' >= 108... ./_autosetup: line 28: type: automake: not found
Desired Outcome
I would like to extract all words within the single quotes, which occur in combination with not found at the end of line.
What I Did and the Problem
Thus, I first grep for not found and pipe the result to sed: (I am using the line of the not found later, thus -n with grep)
grep -n "not found" < textfile.log | sed -n 's/.*\(\'.*\'\).*/\1/p'
With this I am getting two errors: First, that it reached end of file while searching ' and second, that the end of file was unexpected.
I also tried
grep -n "not found" < textfile.log | sed -n 's/.*[\']\(.*\)[\'].*/\1/p'
to only get the word within the single quotes without the quotes. Only getting the same errors.
Thanks for your help.
Use that line instead:
You can use double quotes to quote
'inside the pattern (so you don’t have to backquote them.) That expression also includes the quotes. Without the quotes themselves would require using the parentheses inside the quotes:But I guess you already know that.