I'm writing a bash script to install Phoenix applications. I'd like to add a dependency to the deps
section of my config file without relying on line numbers.
31 # Type `mix help deps` for examples and options.
32 defp deps do
33 [{:phoenix, "~> 1.2.1"},
34 {:phoenix_pubsub, "~> 1.0"},
35 {:phoenix_ecto, "~> 3.0"},
36 {:postgrex, ">= 0.0.0"},
37 {:phoenix_html, "~> 2.6"},
38 {:phoenix_live_reload, "~> 1.0", only: :dev},
39 {:gettext, "~> 0.11"},
40 {:cowboy, "~> 1.0"}]
41 end
In this case, I'd like to turn the ]
in line 40 into a comma, and insert {:foo, "~> 1.0"}]
below line 40. I'm assuming you can use defp deps do
as a marker in a sed or awk expression, and then target the first ]
that follows.
What is the best way to do this?