Skip to main content
Tweeted twitter.com/StackUnix/status/713252696720019456
edited tags; edited title
Link
Gilles 'SO- stop being evil'
  • 865.9k
  • 205
  • 1.8k
  • 2.3k

Bash script : insert into Insert text at specific line number

edited tags; edited title
Link
cuonglm
  • 158.2k
  • 41
  • 342
  • 420

Bash Scriptscript : Insert Into Specific Line Numberinsert into specific line number

Source Link
TheLovelySausage
  • 4.5k
  • 9
  • 35
  • 52

Bash Script : Insert Into Specific Line Number

I'm working on a bash script that will split the contents of a text document depending on the data in the line.

If the contents of the original file were along the lines of

01 line 01 line 02 line 02 line 

How can I insert into line 3 of this file using bash to result in

01 line 01 line text to insert 02 line 02 line 

I'm hoping to do this using a heredoc or something similar in my script

#!/bin/bash vim -e -s ./file.txt <<- HEREDOC :3 | startinsert | "text to insert\n" :update :quit HEREDOC 

The above doesn't work of course but any recommendations that I could implement into this bash script?