1

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:

^.*(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
1

I found the answer. It was simple as hell.

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

(\string).*$

It will select everything after string including the string

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

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
  • "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

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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