0

I cat some files into a markdown parser, and want to pre/ap-pend a head/foot-er. Currently, I do it with a few commands, but would like to do it with a one liner. Here is the command I want to add to...

cat  `find .. -name "*.md" -type f` | marked

That produces the middle of my document, so I would like to do something like...

cat head.template (cat `find ... ` | marked)
Billy Moon
  • 57,113
  • 24
  • 136
  • 237

3 Answers3

3

Try grouping the "source" commands like this:

{ cat header_part ; cat `find ...` ; cat footer_part } | marked

If you only want the middle part parsed:

{ cat header_part ; cat `find ...` | marked ; cat footer_part } > output_file

Thanks to Ansgar Wiechers, prefer $() over backticks:

{ cat header_part ; cat $(find ...) | marked ; cat footer_part ) > output_file
Community
  • 1
  • 1
Mat
  • 202,337
  • 40
  • 393
  • 406
0

This works for me, a combination of $( ... commands ... ) and back ticks.

echo `cat head.html.snippet`  `cat $(find .. -name "*.md" -type f) | marked` `cat foot.html.snippet` > all.htm
Billy Moon
  • 57,113
  • 24
  • 136
  • 237
0

This uses less subprocesses and works if the names contain spaces:

shopt -s globstar; { cat head.html.snippet; cat ../**/*.md | marked; cat foot.html.snippet; } > all.htm

You could also use process substitution:

cat head.html.snippet <(find .. -name '*.md' -exec cat {} \+ | marked) foot.html.snippet > all.htm

Lri
  • 26,768
  • 8
  • 84
  • 82