2. Append Line using Regular Expression/Pattern This will append the line after the line where pattern match is found. Syntax: sed '/PATTERN/ a ' FILE.txt sed -e '/#include/ i #ifndef __CINT__' -e '/#include/ a #endif' ./tpc/tsspars/tsspar.y2018.C sed -i.BAK -e '/#include/ i #ifndef __CINT__' -e '/#include/ a #endif' ./tpc/tsspars/tsspar.y2018.C foreach f (`find StarDb -name "*.C"`) grep '#include "tables/' ${f} if (! $?) then echo "file: ${f}" sed -i.BAK -e '/#include/ i #ifndef __CINT__' -e '/#include/ a #endif' ${f} endif end echo "/home/edwprod/abortive_visit/bin/abortive_proc_call.ksh"|awk -F'/[^/]*$' '{print $1}' /home/edwprod/abortive_visit/bin