Assuming you want to remove all text to the left of keyword1 and all text to the right of keyword2 :
while (<>) { s/.*(keyword1)/$1/; s/(keyword2).*/$1/; print; }
Put this in a perl script and run it like this:
fix.pl original.txt > new.txt
Or if you just want to do this in place, perhaps on multiple files at once:
perl -i.bak -pe 's/.*(keyword1)/$1/; s/(keyword2).*/$1/;' original.txt original2.txt
This will lead to editing, renaming the original to have a .bak extension, use an implicit while-loop with printing, and execute a search and replace pattern before each printing.
To be safe, first check it without the -i option or at least on just one file ...
source share