Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

inserting text into a specific line

Tags:

bash

I've got a text file, and using Bash I wish to insert text into into a specific line.

Text to be inserted for example is !comment: http://www.test.com into line 5

!aaaa
!bbbb
!cccc
!dddd
!eeee
!ffff

becomes,

!aaaa
!bbbb
!cccc
!dddd
!comment: http://www.test.com
!eeee
!ffff
like image 661
user349418 Avatar asked Jul 17 '10 23:07

user349418


1 Answers

sed '4a\
!comment: http://www.test.com' file.txt > result.txt

i inserts before the current line, a appends after the line.

like image 138
Anders Avatar answered Oct 09 '22 17:10

Anders