Is there a way for awk to format data that falls between a certain pattern? For example, I have a file in the following format and I want to print the line containing the Hostname and fields 1 and 5 of the lines that follow.
File looks like:
Hostname is: server1.d34.acme.com
wb01308:x:102:101:John Smith:/home/wb01308:/usr/bin/ksh
u3x2010:x:23620:9249:Jim Davis:/home/u3x2010:/usr/bin/ksh
$ --------------------------------------------------------
Hostname is: server2.d54.acme.com
u3x5163:x:191:102:Jane Doe:/home/u3x5163:/usr/bin/ksh
u3x5063:x:194:102:Austin Powers:/home/u3x5063:/usr/bin/ksh
$ ---------------------------------------------------------
Hostname is: server3.d45.acme.com
u3x2010:x:23620:9249:Jim Davis:/home/u3x2010:/usr/bin/ksh
$ ---------------------------------------------------------
Hostname is: engora2.d52.acme.com
u3x2010:x:23620:9249:Jim Davis:/home/u3x2010:/usr/bin/ksh
$ ---------------------------------------------------------
Hostname is: server4.d25.acme.com
u3x2010:x:23620:9249:Jim Davis:/home/u3x2010:/usr/bin/ksh
$ ---------------------------------------------------------
I need the output to look like:
Hostname is: server1.d34.acme.com
wb01308 John Smith
u3x2010 Jim Davis
Hostname is: server2.d54.acme.com
u3x5163 Jane Doe
u3x5063 Austin Powers
Hostname is: server3.d45.acme.com
u3x2010 Jim Davis
Hostname is: engora2.d52.acme.com
u3x2010 Jim Davis
Hostname is: server4.d25.acme.com
u3x2010 Jim Davis
I know I need to use: awk -F: '{print $1, $5}' filename
I have a question on including the line containing Hostname.
Thanks,
CSTORM
File looks like:
Hostname is: server1.d34.acme.com
wb01308:x:102:101:John Smith:/home/wb01308:/usr/bin/ksh
u3x2010:x:23620:9249:Jim Davis:/home/u3x2010:/usr/bin/ksh
$ --------------------------------------------------------
Hostname is: server2.d54.acme.com
u3x5163:x:191:102:Jane Doe:/home/u3x5163:/usr/bin/ksh
u3x5063:x:194:102:Austin Powers:/home/u3x5063:/usr/bin/ksh
$ ---------------------------------------------------------
Hostname is: server3.d45.acme.com
u3x2010:x:23620:9249:Jim Davis:/home/u3x2010:/usr/bin/ksh
$ ---------------------------------------------------------
Hostname is: engora2.d52.acme.com
u3x2010:x:23620:9249:Jim Davis:/home/u3x2010:/usr/bin/ksh
$ ---------------------------------------------------------
Hostname is: server4.d25.acme.com
u3x2010:x:23620:9249:Jim Davis:/home/u3x2010:/usr/bin/ksh
$ ---------------------------------------------------------
I need the output to look like:
Hostname is: server1.d34.acme.com
wb01308 John Smith
u3x2010 Jim Davis
Hostname is: server2.d54.acme.com
u3x5163 Jane Doe
u3x5063 Austin Powers
Hostname is: server3.d45.acme.com
u3x2010 Jim Davis
Hostname is: engora2.d52.acme.com
u3x2010 Jim Davis
Hostname is: server4.d25.acme.com
u3x2010 Jim Davis
I know I need to use: awk -F: '{print $1, $5}' filename
I have a question on including the line containing Hostname.
Thanks,
CSTORM