Giovanni
Giovanni

Reputation: 37

daily script to edit markdown files

I am considering creating a daily script to go through hundreds of Markdown files (on a Mac) and perform simple operations such as:

  1. find and replace strings,
  2. calculate days elapsed from a particular date and write them in the files,
  3. generate reports based on today's date.

I was assuming a Python would be the best option but somebody told me that a bash script using grep, sed etc is the best solution in terms of speed, being able to scale up, portability etc. What is your expert advice?

  1. Python
  2. Bash script
  3. Performance equivalent for hundreds or even thousands of txt files, so mostly a matter of preference

Thanks!!

Upvotes: 1

Views: 696

Answers (1)

xjcl
xjcl

Reputation: 15309

Depends on exactly what to replace, meaning how hard the "find" and "replace" operation are to represent -- complex logic should better be managed in a proper programming language like Python.

Complex date calculations are a bit awkward in bash, but can be done. Python might be somewhat more readable here.

Speed: Likely not going to matter since you are I/O-limited, and only doing it once a day. But if it matters, Python would of course be slower.

Portability: Python would be portable to Windows, command line tools like sed less so. sed would produce shorter code though.

In conclusion, both options are totally appropriate.

Upvotes: 1

Related Questions