How do I insert a line in the middle of a file in BASH?

I have tried

sed '/6/a text_to_inserted' file > newfile

but this inserts test_to_insert at random places in file and i want it in specific location, which is line 6.

can anyone help....

This solution will insert the new line between 5th and 6th line.

sed '6i\
This is the new line
' file

/usr/bin/ex - "$targfile" << _EOF_ 1>/dev/null 2>&1
${linenum_below}i
$source
.
wq!
_EOF_
if [[ $? -ne 0 ]]; then
# add error log here
fi

/6/ is a regular expression which matches the digit, 6. If you want line 6, leave out the slashes.

sed '6a\
text_to_insert
'

I have a $(whoami) in the line to be inserted and

sed '6a\
text_to_insert
'

is not recognizing it. it inserts $(whoami) instead of the username
any ideas??

Substitution and expansion is not performed within single quotes.

thanks johnson, much appreciate it