Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I remove the text before and after a particular character?

Tags:

regex

perl

I have been trying to remove the text before and after a particular character in each line of a text. It would be very hard to do manually since it contain 5000 lines and I need to remove text before that keyword in each line. Any software that could do it, would be great or any Perl scripts that could run on Windows. I run Perl scripts in ActivePerl, so scripts that could do this and run on ActivePerl would be helpful.

Thanks

like image 960
riyaj Avatar asked Nov 28 '25 22:11

riyaj


1 Answers

I'd use this:

$text =~ s/ .*? (keyword) .* /$1/gx;
like image 52
Leon Timmermans Avatar answered Nov 30 '25 22:11

Leon Timmermans