Using sed :
sed -i -e '10a\ new stuff' file
Using bash :
IFS=$'\n' i=0 while read -r line; do i=$((i+1)) if test $i -eq 10; then echo "new stuff" else echo "$line" fi done <file >file.tmp mv file.tmp file
Please note: I'm not sure if you mean the insert on line 10 or line 11, so double check the places I wrote 10 above. You may need 9 for the sed command or 11 for the bash version.
In perl you can use the $NR variable.
open FILEHANDLE, "<file"; while (<FILEHANDLE>) { if ($NR == 10) {
And in awk , he's NR .
awk 'NR != 10 { print } NR == 10 { print "Something else" }' file
But note that you can find and replace an empty string, for example
sed -i -e 's/^$/replacement text/' file
source share