This command used to get the line number of a word in the file.
#grep -n "word" asd1.sh | cut -f1 -d:
To get the output in a variable use the below command:
#VAR='grep -n "word" asd1.sh | cut -f1 -d:'
Below command will add 1 to result line. bc is the command line calculator.
#echo `grep -n "word" asd1.sh | cut -f1 -d:` + 1 | bc
Command to add text in a file at given location
#awk 'NR==3{print "newline"}1' asd1.sh
test.sh
findline=`grep -n "log4j:configuration" jboss-log4j.xml | cut -f1 -d:`
addline=`echo $findline+1| bc`
sed ""${addline}"i\ $appender" jboss-log4j.xml > test.txt
The above command will be useful for adding the appender to Jboss log4j xml file during deployment.