1

These are the contents of the text file:

cat
dog
elephant
cat lion
cat tiger
penguin
penguin emperor
zebra

I want to remove the line contain just cat and retain cat lion and cat tiger lines.

There could be nth number of spaces after the word cat in the cat line, it could be zero or 10.

Any ideas how it can be done?

1

1 Answer 1

2

It's fairy simple with sed:

sed -e '/^cat$/d' <file

/^cat$/ only match line which contains only cat, then delete that line.

or awk:

awk '!/^cat$/' <file

or grep:

grep -v '^cat$' <file

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .