Posts Tagged ‘sed’

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).

sed: batch file rename

Friday, October 16th, 2015

Deleting plus sign from multiple filenames.

Is:

-rw-r--r--. 1 root root  153771 Oct 16 10:11 node-01-1444744974.2017874_in_+38050190.ogg
-rw-r--r--. 1 root root  167217 Oct 16 10:11 node-03-1444736219.1609540_in_+38050190.ogg
-rw-r--r--. 1 root root  141165 Oct 16 10:11 node-07-1444726601.1585794_in_+38073454.ogg
-rw-r--r--. 1 root root  193136 Oct 16 10:11 node-27-1444726479.1648259_in_+38073454.ogg

Must be:

-rw-r--r--. 1 root root  153771 Oct 16 09:58 node-01-1444744974.2017874_in_38050190.ogg
-rw-r--r--. 1 root root  167217 Oct 16 09:58 node-03-1444736219.1609540_in_38050190.ogg
-rw-r--r--. 1 root root  141165 Oct 16 09:56 node-07-1444726601.1585794_in_38073454.ogg
-rw-r--r--. 1 root root  193136 Oct 16 09:57 node-27-1444726479.1648259_in_38073454.ogg

Script:

#!/bin/bash

for i in *ogg
do
	mv "$i" "`echo $i | sed 's/\+//'`"
done