Archive for February 5th, 2016

sed: add line starting with 2 tabs before another matching line

Friday, February 5th, 2016

Add a line Sipaddheader(X-DSTPHONE:${E}); before lines containing zabbix.

sed '/zabbix/a Sipaddheader(X-DSTPHONE:${E});' extensions.ael > extensions2.ael

Add the same but starting with 2 tabs seems to be not hard. But the problem is that not all sed versions support \t parameter.

So, neither of these worked for me:

sed '/zabbix/a \t\tSipaddheader(X-DSTPHONE:${E});' extensions.ael > extensions2.ael
sed '/zabbix/a \t\t Sipaddheader(X-DSTPHONE:${E});' extensions.ael > extensions2.ael
sed '/zabbix/a\t\t Sipaddheader(X-DSTPHONE:${E});' extensions.ael > extensions2.ael

The solution is as follows: insert a literal tab pressing Ctrl-V and then Tab (not shown in the listing).