Insert a new line each x lines Regex Find: ((?:.*\r?\n){4}) Regex Replace: $0\n Remove all lines not containing 'word' ^((?!word).)*$/gms