Bash script to add some line to a file at specific line number

I wrote this example to show how to append JAVA_OPTS parameters to startup.sh of tomcat



#!/bin/bash

NLINE=2
s=" export JAVA_OPTS=\"$JAVA_OPTS -Xms1024m -Xmx1024m -XX:MaxPermSize=256m\""
sp=" "
awk -vn="$NLINE" -vs="$s" -vsp="$sp" 'NR==n{$0=$0 sp s}1' startup.sh >temp
mv temp startup.sh



Sp is space given so that if something exists in that line it will give some space and
append our command or string