I am selecting specific line and I want it to be removed with all the text and lines after it.

Code I use to select the line containing needed string:


Also I another one to remove it and text before it for another string.

It would be great if I could replace all the text and lines with a one custom line.

I've tried adding .* and \r\n, but nothing is working..

  • It would even be great to simply remove/replace all after specific characters like "?>" – Simon S Jan 8 '17 at 23:46

I found the answer. It was simple as hell.

This simple line did what I wanted, maybe it will help for someone else too.


It will select everything after string including the string

  • 1
    Please describe where do you write (\string).*$ ? – qqqqq Feb 27 '17 at 22:13

If I understand your question this script answers the first problem. For the second problem use nearly the same script and run diff on the two files.

#!/bin/bash -
gawk '
# /pattern/ { action } 
BEGIN { flag = 0 }
/^.*foo.*$/ { flag++ }
if (flag == 0)
    print $0 
' file
  • how can I use this on notepad++? – Simon S Jan 8 '17 at 23:50
  • 1
    "If I understand your question" You didn't. OP is using Windows and Notepad++ not bash. – DavidPostill Jan 9 '17 at 11:27
  • Please read the question again carefully. Your answer does not answer the original question. – DavidPostill Jan 9 '17 at 11:27

Go to the line. Ctrl-G.
Ctrl-H for search and replace.
Enter .*$ in "Find". Blank in "Replace with" Select Regular Expression and check ".matches newlines" Hit Replace

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.