Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select subdomains using print command

cat a.txt

a.b.c.d.e.google.com
x.y.z.google.com
rev a.txt | awk -F. '{print $2,$3}' | rev

This is showing:

e google
x google

But I want this output

a.b.c.d.e.google
b.c.d.e.google
c.d.e.google
e.google
x.y.z.google
y.z.google
z.google

1 Answers

With your shown samples, please try following awk code. Written and tested in GNU awk should work in any awk.

awk '
BEGIN{
  FS=OFS="."
}
{
  nf=NF
  for(i=1;i<(nf-1);i++){
    print
    $1=""
    sub(/^[[:space:]]*\./,"")
  }
}
' Input_file
like image 126
RavinderSingh13 Avatar answered Apr 22 '26 23:04

RavinderSingh13