FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > CentOS > CentOS

 
 
LinkBack Thread Tools
 
Old 07-09-2008, 04:39 PM
"Sean Carolan"
 
Default Need help with awk one-liner

This awk command pulls URLs from an apache config file, where $x is
the config filename.

awk '/:8008/root/ {printf $3 " "}' $x

The URL that is output by the script looks something like this:

ajpv12://hostname.network.company.com:8008/root

Is there a way to alter the output so it only shows "hostname" by
itself? Do I need to pipe this through awk again to clean it up?
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 07-09-2008, 04:55 PM
"Ross S. W. Walker"
 
Default Need help with awk one-liner

Sean Carolan wrote:

> This awk command pulls URLs from an apache config file, where $x is
> the config filename.
>
> awk '/:8008/root/ {printf $3 " "}' $x
>
> The URL that is output by the script looks something like this:
>
> ajpv12://hostname.network.company.com:8008/root
>
> Is there a way to alter the output so it only shows "hostname" by
> itself? Do I need to pipe this through awk again to clean it up?

awk '/:8008/root/ {printf $3 " "}' $x | sed 's/.*/(.*):.*/1/'

-Ross

__________________________________________________ ____________________
This e-mail, and any attachments thereto, is intended only for use by
the addressee(s) named herein and may contain legally privileged
and/or confidential information. If you are not the intended recipient
of this e-mail, you are hereby notified that any dissemination,
distribution or copying of this e-mail, and any attachments thereto,
is strictly prohibited. If you have received this e-mail in error,
please immediately notify the sender and permanently delete the
original and any copy or printout thereof.

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 07-09-2008, 05:03 PM
"Sean Carolan"
 
Default Need help with awk one-liner

>> The URL that is output by the script looks something like this:
>>
>> ajpv12://hostname.network.company.com:8008/root
>>
>> Is there a way to alter the output so it only shows "hostname" by
>> itself? Do I need to pipe this through awk again to clean it up?
>
> awk '/:8008/root/ {printf $3 " "}' $x | sed 's/.*/(.*):.*/1/'

That worked well. If I have three matches from the awk command, how
would you alter this so sed will output all three hostnames?
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 07-09-2008, 05:13 PM
"Sean Carolan"
 
Default Need help with awk one-liner

The awk output that was piped into to the sed command looks like this:

ajpv12://host1.domain.company.com:8008/root
ajpv12://host2.domain.company.com:8008/root
ajpv12://host3.domain.company.com:8008/root
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 07-09-2008, 05:13 PM
"Sean Carolan"
 
Default Need help with awk one-liner

those are supposed to be tab-separated urls, all on one line.
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 07-09-2008, 05:23 PM
"Ross S. W. Walker"
 
Default Need help with awk one-liner

Sean Carolan wrote:

> those are supposed to be tab-separated urls, all on one line.

If 'ajpv12://' and ':8008/root' are always going to be the same:

awk '/:8008/root/ {printf $3 " "}' $x | sed 's/ajpv12:////g' | sed 's/:8008/root//g'

If these change then your going to need either a more complex awk,
or more complex sed expression.

-Ross

__________________________________________________ ____________________
This e-mail, and any attachments thereto, is intended only for use by
the addressee(s) named herein and may contain legally privileged
and/or confidential information. If you are not the intended recipient
of this e-mail, you are hereby notified that any dissemination,
distribution or copying of this e-mail, and any attachments thereto,
is strictly prohibited. If you have received this e-mail in error,
please immediately notify the sender and permanently delete the
original and any copy or printout thereof.

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 07-09-2008, 05:27 PM
"Sean Carolan"
 
Default Need help with awk one-liner

> If 'ajpv12://' and ':8008/root' are always going to be the same:
>
> awk '/:8008/root/ {printf $3 " "}' $x | sed 's/ajpv12:////g' | sed 's/:8008/root//g'
>
> If these change then your going to need either a more complex awk,
> or more complex sed expression.
>
> -Ross

Marvelous. Thanks for taking the time to help me Ross. This is going
to be extremely helpful.

Sean
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 07-10-2008, 08:39 AM
Mikael Fridh
 
Default Need help with awk one-liner

On Wed, Jul 09, 2008 at 12:13:13PM -0500, Sean Carolan wrote:
> The awk output that was piped into to the sed command looks like this:
>
> ajpv12://host1.domain.company.com:8008/root
> ajpv12://host2.domain.company.com:8008/root
> ajpv12://host3.domain.company.com:8008/root

awk '/:8008/root/ {printf "%s ", gensub(/ajpv12://(.*):8008/root/, "1", 1, $3) } END { printf "
" }'

if you give an exact example of your input it would be easier but I
guess you can crunch the above example to do exactly what you want.

Match other ports and protocols:
awk '/:[[:digit]]+/root/ {printf "%s ", gensub(/w+://(.*):[[:digit:]]+/root/, "1", 1, $3) } END { printf "
" }'

takes input:
foo bar URL baz

output:
URL URL URL


--
Fridh
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 07-10-2008, 06:06 PM
Denis
 
Default Need help with awk one-liner

Sean Carolan wrote:

The awk output that was piped into to the sed command looks like this:

ajpv12://host1.domain.company.com:8008/root
ajpv12://host2.domain.company.com:8008/root
ajpv12://host3.domain.company.com:8008/root
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos



for the sample data you gave the following worked for me:

gawk -F/ '/:8008/root/ {split($3,hostname,".") ; print hostname[1]}'
urls


--
Denis Becker
Information Technology - Engineering
MN State Univ., Mankato
Mankato, MN
ph: 507-389-5617
fx: 507-389-5002

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 

Thread Tools




All times are GMT. The time now is 06:13 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org