I have a file with different lines, among which I have some lines like
173.194.034.006.00080-138.096.201.072.49934
the pattern is 3 numbers and then a dot and then 3 numbers and then a dot, etc.
I want to use awk, grep, or sed for this purpose. How do I express this regular expression?
Assuming you want to get lines with 1 series like 123. exists, do
If you want 2 series like 123.345., then do
etc, etc.
Each
[0-9]means match only one occurance of characters in the range between 0-9 (0,1,2,3,4,5,6,7,8,9).Because the ‘.’ char has a special meaning in a normal grep regexp, you nave to escape it like
\.to indicate “Just match the ‘.’ char (only!) 😉There are fancy extensions to grep that allow you to specify the pattern once, and include a qualifier like
{3}or sometimes\{3\}(to indicate 3 repetitions). But this extension isn’t portable to older Unix like Solaris, AIX, and others.Here’s a simple test to see if your system supports qualifiers. (Super Grep-heads are welcome to correct my terminology :-).
The first test should fail, the 2nd will succeed if your grep supports qualifiers.
It doesn’t hurt to learn the long-hand solution (as above), and you can be sure this will work with any grep.
IHTH.