-3

I have a below word list:

www.home.example.com
www.example.com
home.example.com
google.com
example.com
child.example.com
sameer.example.com
sameer.google.com

I need a regex which only matches child domains of example.com, meaning I need the below answer:

www.home.example.com
home.example.com
child.example.com
sameer.example.com

But without using egrep -v option.

I have tried egrep -i '(([(a-zA-Z0-9\-\.|^www)]*)\.example\.com)' but did not work. Any help will be highly appreciated.

manjesh23
  • 369
  • 1
  • 4
  • 21

2 Answers2

1

grep approach (with PCRE):

grep -Pi '(?<!www)\.example\.com' file

without PCRE:

cat file | grep -Ei '\.example\.com' | grep -Ev '^w{3}\.example\.com'

The output:

www.home.example.com
home.example.com
child.example.com
sameer.example.com
RomanPerekhrest
  • 88,541
  • 4
  • 65
  • 105
0

I'm not sure what it is you want to exclude, since you say you want to match only those in a given domain. If the words are in a file on separate lines, shouldn't a match locked to the end-of-line do?

grep -e '\.example\.com$' domains 

If you want to exclude something after that, then just use grep -v, it's part of POSIX anyway.

ilkkachu
  • 6,221
  • 16
  • 30