I need to extract data from a page in redmine formatted in textile in order to set variables in a bash script. I want to use AWK to do so. Here is the content of the page:
$ cat mypage.redmine
h1. My Awesome page
h2. A section
hello
there
table(metadata).
|TITLE |An awesome title! |
|VERSIONNUM |1 |
|VERSIONDATE |2017-06-16 |
|AUTHOR |Me! |
table(otherthing).
|RECORD1 |A value. |
|RECORD2 |Another value |
h2. Another section
We say things.
The information of interest is in the table of class "metadata".
I would like the output to be:
TITLE="An awesome title!"
VERSIONNUM="1"
VERSIONDATE="2017-06-16"
AUTHOR="Me!"
... so that I can directly call declare
in my shell script on this output to set variables TITLE
, VERSIONNUM
, etc.
Here is what I got so far:
$ awk 'BEGIN { FS = "|" } { if(NF == 4) print $2 "=" "\"" $3 "\"" }' < mypage.redmine
Which renders:
TITLE ="An awesome title! "
VERSIONNUM ="1 "
VERSIONDATE ="2017-06-16 "
AUTHOR ="Me! "
RECORD1 ="A value. "
RECORD2 ="Another value "
Which is not what I look for... I need the one liner to work only on the table(metadata) and to get rid of trailing spaces.
How can I do so?
Edit: I forgot the quotes in the rendering of my attempt.