In a shell script, I get the certain number of a line in a file and store it in a variable using the code below:
res=$(grep -n '123' somefile.txt | sed 's/^\([0-9]\+\):.*$/\1/')
Now I want to write in 3 lines after this line, so I used these codes :
sed -i '$res\anything' somefile.txt
sed -i '$resianything' somefile.txt
but they don't work. It seems that sed
doesn't accept variables.
How can I solve it? Is there any alternative way?