Off topic: When I was on Linux, I saw last | grep [a-zA-Z] | grep -v 'wtmp' | wc -l. I was wondering if I could do it with just one grep, so I thought about it. Use regular expression to match a certain line that does not contain a certain word (such as wtmp), but the result is not figured out.
js
/^(?!.*wtmp)/
Matching does not contain, this difficulty should be relatively large for regular expressions, because this condition may be true at this position, but it may not be true at the next position! However, regular expressions will return any string that satisfies pattern
For As an example of your question, I recommend using
awk
to implement:awk
It can provide more flexible logical processing and is more readable. Compared with a single regular expression, I think awk is a better choice in the scenario in the question, but if it is implemented in other languages, you may have to refer to In other languages