sed -i "5a # This is a test file.\n# Test insert line into this file." 1.txt
#!/bin/bash
n=0
cat 1.txt |while read line
do
n=$[$n+1]
if [ $n -eq 5 ];then
echo $line >> 2.txt
echo -e "# this is a test file.\n# test insert line into this file." >> 2.txt
else
echo $line >> 2.txt
fi
done
\mv 2.txt 1.txt
原文:http://blog.51cto.com/12606610/2136297