# Use sed to insert three lines of text after the line that matches a certain pattern

Discussion in 'Scripting' started by anansay, Sep 10, 2020.

1. ### anansay MDL Junior Member

Jul 13, 2020
86
7
0
I have a set of files with file extension ovpn and wish to insert into each of them the following three lines:

The above are to be placed after this line:

The desired output should be:

My attempt is:

Code:
sed -i -e '/auth SHA512/a\' \
-e '\n\nscript-security 2\nup /etc/openvpn/update-resolve-conf\ndown /etc/openvpn/update-resolv-conf\n' \
*.ovpn
However the above commands add two blank lines after "auth SHA512" and a blank line after "down /etc/openvpn/update-resolv-conf".

Can someone show me how to not add blank lines after "auth SHA512" and a blank line after "down /etc/openvpn/update-resolv-conf"?

2. ### abbodi1406 MDL KB0000001

Feb 19, 2011
11,260
48,624
340
remove the first \n and the last one