satch_boogie satch_boogie - 5 months ago 12
Linux Question

how does - grep -E -o "average:.{0,5}" work

$

uptime


12:03:38 up 2 days, 19:03, 1 user,
load average: 1.87, 2.40, 2.20


$ uptime |
grep -E -o "average:.{0,5}"
\

average: 1.53

i know that -o = show only matching but how do "
.{0,5}
" work here ?
Thank you

Answer

-E tells grep to use regular expressions instead of traditional string matching.

. in a regular expression means "any character". {0,5} is a repetition statement and means "the symbol before can be repeated 0 to 5 times".

.{0,5} means "match any 0 to 5 characters".

In your example, it matches 1.53 which is in fact 5 characters long (note the space before the 1!).

Comments