Skip to content

Instantly share code, notes, and snippets.

@DoonDoony
Created December 9, 2019 05:44
Show Gist options
  • Save DoonDoony/a6203bfd2e26179090fd6b0942a05c15 to your computer and use it in GitHub Desktop.
Save DoonDoony/a6203bfd2e26179090fd6b0942a05c15 to your computer and use it in GitHub Desktop.
Insert a line into specific line number with GUN sed

Suppose you insert a line of code below.

import sys

Here's what the one-line code is to be inserted into. (app.py)

  1 import os
  2 <insert the code snippet here>
  3
  4
  5 sys.path.append('/code')
  6 ROOT_DIR = os.path.dirname(os.path.abspath(__file__))

Use sed / GNU sed only, try brew install gnu-sed

$ gsed -i '2i\import sys' app.py

Profit!

  1 import os
  2 import sys
  3
  4
  5 sys.path.append('/code')
  6 ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment