Skip to main content
1 of 3
John1024
  • 76.4k
  • 12
  • 176
  • 165

Let's take this as a test file:

$ cat testfile
1.2.3.4 5.6.7.8 9.10.11.12  Keep
1.2.3.4 5.6.7.8 9.10.11     Bad: Missing 1
1.2.3.4 5.6.7.8 9.10.11.12. Bad: Extra period

Using grep

To select lines with exactly nine periods:

$ grep -E '^([^.]*\.){9}[^.]*$' testfile
1.2.3.4 5.6.7.8 9.10.11.12  Keep

Using sed

$ sed -En '/^([^.]*\.){9}[^.]*$/p' testfile
1.2.3.4 5.6.7.8 9.10.11.12  Keep

Using awk

$ awk '/^([^.]*\.){9}[^.]*$/' testfile
1.2.3.4 5.6.7.8 9.10.11.12  Keep
John1024
  • 76.4k
  • 12
  • 176
  • 165