Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

113
Views
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

Thank You in Advance

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

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
over 4 years ago · Santiago Trujillo Report

0

Here is one more awk solution:

awk -F. '{while (!/^[^.]+\.[^.]+$/) {print; sub(/^[^.]+\./, "")}}' file

a.b.c.d.e.google.com
b.c.d.e.google.com
c.d.e.google.com
d.e.google.com
e.google.com
x.y.z.google.com
y.z.google.com
z.google.com
over 4 years ago · Santiago Trujillo Report

0

Using sed

$ sed -n '/^/p;:a;s/[a-z]*\.\(.*[a-z]\.[a-z]*\.[a-z]*\)/\1/p;ta;' input_file
a.b.c.d.e.google.com
b.c.d.e.google.com
c.d.e.google.com
d.e.google.com
e.google.com
x.y.z.google.com
y.z.google.com
z.google.com
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!