Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using:

grep -n -H -o -R -e textword .

List all file recursively under directory '.' with string 'textword' and show the file, line and only portion matching.

I need to remove lines that matched the text using a Linux command.

share|improve this question
Did you look into sed? – Bernhard Apr 25 '13 at 20:08
up vote 1 down vote accepted
find . -type f -exec sed -r -i "/textword/d" {} +

Remember that the search text is interpreted as a regexp by sed (with the -r option), so it might need escaping.

Use sed -i.backup to backup original files as <filename>.backup.

share|improve this answer

With GNU find and sed you could:

find . -type f -print0 | xargs -0 sed -i '/^FIND$/d'
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.