2 replaced http://unix.stackexchange.com/ with https://unix.stackexchange.com/
source | link

Using awkUsing awk is probably the best here since it lets you express your thought clearly (strip the tags, there must be at most 4 words left, not including the first column). But you can also do this with grep, since it's just a matter of filtering lines and the filter can be described by a regular expression.

grep -vE '^ *[^ ]+((<[^>]*>| )+[^<> ]+){5}'
  • -v: exclude matching lines
  • -E: use extended regular expression syntax
  • ^ *[^ ]+ matches the first word at the beginning of the line
  • (…){5} means 5 or more of what's in the parentheses
  • (<[^>]*>| )+ matches a non-empty sequence of spaces and tags
  • [^<> ]+ matches a non-tag word

Using awk is probably the best here since it lets you express your thought clearly (strip the tags, there must be at most 4 words left, not including the first column). But you can also do this with grep, since it's just a matter of filtering lines and the filter can be described by a regular expression.

grep -vE '^ *[^ ]+((<[^>]*>| )+[^<> ]+){5}'
  • -v: exclude matching lines
  • -E: use extended regular expression syntax
  • ^ *[^ ]+ matches the first word at the beginning of the line
  • (…){5} means 5 or more of what's in the parentheses
  • (<[^>]*>| )+ matches a non-empty sequence of spaces and tags
  • [^<> ]+ matches a non-tag word

Using awk is probably the best here since it lets you express your thought clearly (strip the tags, there must be at most 4 words left, not including the first column). But you can also do this with grep, since it's just a matter of filtering lines and the filter can be described by a regular expression.

grep -vE '^ *[^ ]+((<[^>]*>| )+[^<> ]+){5}'
  • -v: exclude matching lines
  • -E: use extended regular expression syntax
  • ^ *[^ ]+ matches the first word at the beginning of the line
  • (…){5} means 5 or more of what's in the parentheses
  • (<[^>]*>| )+ matches a non-empty sequence of spaces and tags
  • [^<> ]+ matches a non-tag word
1
source | link

Using awk is probably the best here since it lets you express your thought clearly (strip the tags, there must be at most 4 words left, not including the first column). But you can also do this with grep, since it's just a matter of filtering lines and the filter can be described by a regular expression.

grep -vE '^ *[^ ]+((<[^>]*>| )+[^<> ]+){5}'
  • -v: exclude matching lines
  • -E: use extended regular expression syntax
  • ^ *[^ ]+ matches the first word at the beginning of the line
  • (…){5} means 5 or more of what's in the parentheses
  • (<[^>]*>| )+ matches a non-empty sequence of spaces and tags
  • [^<> ]+ matches a non-tag word