I posted previously about a small script that I'm working on. I eventually figured out that problem. Now I'm running into a different one. Hopefully you can help.
Some setup: I have a short list stored as a markdown file.
|One Hundred Years of Solitude|Gabriel García Márquez|-|-|-|-|1967|
|Moby-Dick|Herman Melville|-|-|-|-|1851|
|Frankenstein|Mary Shelley|-|-|-|-|1818|
|On the Road|Jack Kerouac|-|-|-|-|1957|
|The Turn of the Screw|Henry James|-|-|-|-|-|
I've figured out how to feed the file through cat, sed, xargs, and awk.
cat list.md | sed -e 's/^\|//' -e 's/\|$//' -e 's/^ *//' \
-e '/^\:/d' -e '/\'Title'/d' -e '/^\r/d' -e '/^$/d' | xargs -0 echo | \
awk -F '|' '{print "----"} {print "Title:", $1} {print "Author:", $2} \
{print "Date Begun:", $4} {print "Date Finished:", $5}'
That command returns this:
----
Title: One Hundred Years of Solitude
Author: Gabriel García Márquez
Date Begun: -
Date Finished: -
----
Title: Moby-Dick
Author: Herman Melville
Date Begun: -
Date Finished: -
----
Title: Frankenstein
Author: Mary Shelley
Date Begun: -
Date Finished: -
----
Title: On the Road
Author: Jack Kerouac
Date Begun: -
Date Finished: -
----
Title: The Turn of the Screw
Author: Henry James
Date Begun: -
Date Finished: -
What I'd like to do is incorporate this into a script that I can run with an argument like 'books Melville' that will run the above commands, pipe it into grep, search for the argument (preferably either a word or a string), and then return the entire line. As in, if I type 'books Melville', the script would return
----
Title: Moby-Dick
Author: Herman Melville
Date Begun: -
Date Finished: -
Currently, if I type 'books Melville', all that it returns is 'Author: Herman Melville'.
Sorry for the long post.
Edit with another apology: I forgot to mention that I'm on OSX.