Reputation: 16428
I have the following string
Local intf Local circuit Dest address VC ID Status
------------- -------------------------- --------------- ---------- ----------
Gi36/1 Eth VLAN 3018 181.181.181.181 3018 UP
10.65.220.180#
--- 19:58:22 ---
482: linuxserver: 2014-07-07T19:58:22: %framework-5-NOTICE: %[pname=TRP-__taskid1]: id: testcase_info_id37
483: linuxserver: 2014-07-07T19:58:22: %framework-5-NOTICE: %[pname=TRP-__taskid1]: starttime: 2014-07-07 19:58:22
484: linuxserver: 2014-07-07T19:58:22: %framework-5-NOTICE: %[pname=TRP-__taskid1]: name: testcase_info_id37
485: linuxserver: 2014-07-07T19:58:22: %framework-5-NOTICE: %[pname=TRP-__taskid1]: Starting execution of subtest testcase_info_id37
+++ 19:58:22 +++
Local intf Local circuit Dest address VC ID Status
------------- -------------------------- --------------- ---------- ----------
Gi36/1 Eth VLAN 3018 181.181.181.181 3018 UP
I want to replace all the line which contains characters like "linuxserver" in it.
I have tried in vi like below.
:%s/.*linuxserver.*//g
But, after replacement, I am getting output as
Local intf Local circuit Dest address VC ID Status
------------- -------------------------- --------------- ---------- ----------
Gi36/1 Eth VLAN 3018 181.181.181.181 3018 UP
10.65.220.180#
--- 19:58:22 ---
//A new line here
//A new line here
//A new line here
//A new line here
+++ 19:58:22 +++
Local intf Local circuit Dest address VC ID Status
------------- -------------------------- --------------- ---------- ----------
Gi36/1 Eth VLAN 3018 181.181.181.181 3018 UP
I want it to be like as follows,
Local intf Local circuit Dest address VC ID Status
------------- -------------------------- --------------- ---------- ----------
Gi36/1 Eth VLAN 3018 181.181.181.181 3018 UP
10.65.220.180#
--- 19:58:22 ---
+++ 19:58:22 +++
Local intf Local circuit Dest address VC ID Status
------------- -------------------------- --------------- ---------- ----------
Gi36/1 Eth VLAN 3018 181.181.181.181 3018 UP
How i can achieve this ? Thanks in advance.
Upvotes: 0
Views: 114
Reputation: 16938
The :global
command is most appropriate for your problem (:g/linuxserver/d
), but here is the reason why vim gave you empty lines instead of deleting them. The .
does not match new lines (see :help :regex):
. (with 'nomagic': \.) */.* */\.*
Matches any single character, but not an end-of-line.
\n matches an end-of-line */\n*
When matching in a string instead of buffer text a literal newline
character is matched.
So in order to delete the lines, change your regex as follows:
:%s/.*linuxserver.*\n//
Oh, and the /g
modifier doesn't make sense in your case because you already match the whole line (.*
... .*
).
Upvotes: 4