1

I used \A.*$\r\n to remove first line in text, using Powergrep, Is there a way to multiply this command? Need to select and remove first 3 lines in text, and last 3 lines in text?

Tried this solution Perl/regex to remove first 3 lines and last 3 lines of a string but it doesn't work in Powergrep.

Jim8645
  • 181
  • 3
  • 15

3 Answers3

0

Check this for the first three lines (demo on regex101.com):

\A(^.*$\r?\n){3}

and this for the last three (demo):

(^.*$\r?\n){3}\z
w.b
  • 11,026
  • 5
  • 30
  • 49
0

Try this pattern:

\A(.*\r?\n){3}|(\r?\n.*){3}\z

Test it with Rubular here: http://rubular.com/r/MfiF4tRyk3

Bart Kiers
  • 166,582
  • 36
  • 299
  • 288
  • I tested in Powergrep, I confirm this one worked, the one from first answer didn't, thank you both for the help. – Jim8645 Aug 30 '15 at 12:45
0

You cannot use grep for that. grep(1) works in a line equality assuption. You have a better solution with sed(1) in the following code:

sed -e '1d;$d' file.txt >output.txt

I you want to delete lines 1-3 and ($-3)-$ try

sed -e '1,3d;$-3,$d' file.txt >output.txt

Sorry, I have never used powergrep so I cannot help you in that way.

Luis Colorado
  • 10,974
  • 1
  • 16
  • 31