improved sed expression for testing and filtering