I'm trying to come up with something that will delete all text to end of line from a given character onwards.
E.g. in the example below I want to keep only the IP address:
192.168.2.121/32 -m comment --comment "blah blah bye bye" -j DROP
10.1.3.207 -m comment --comment "much longer comment with all kinds of stuff" -j DROP
172.16.1.0/24 -m comment --comment "Drop this range" -j DROP
The pattern to remove from is -m
, i.e., reading from left, the first "-" encountered. From that "-" to end-of-line should be deleted on every line in the file.
I'm stumped on this one, guidance would be appreciated.
Cutting (Deleting) dd - Delete (cut) the current line, including the newline character. 3dd - Delete (cut) three lines, starting from the line where the cursor is positioned, d$ - Delete (cut) everything from the cursor to the end of the line.
Explanation: If the cursor is placed at the end of the file, then delete button is pressed to delete the text. To delete the file, we should use delete button. To delete the selected text, delete or backspace is used.
The command dw will delete from the current cursor position to the beginning of the next word character. The command d$ (note, that's a dollar sign, not an 'S') will delete from the current cursor position to the end of the current line. D (uppercase D) is a synonym for d$ (lowercase D + dollar sign). Save this answer.
A global command would be a good fit
:g/-/norm nD
Explanation
:g : Start a Global Command (:h :g for extra help on global commands)
/- : Search for -
/norm nD : Execute nD in Normal Mode where
n - jumps to the match
D - delete to the end of the line
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With