This awk command pulls URLs from an apache config file, where $x is the config filename.
awk '/:8008/root/ {printf $3 "\t"}' $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?
Sean Carolan wrote:
This awk command pulls URLs from an apache config file, where $x is the config filename.
awk '/:8008/root/ {printf $3 "\t"}' $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 "\t"}' $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.
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 "\t"}' $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?
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
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 "\t"}' $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.
If 'ajpv12://' and ':8008/root' are always going to be the same:
awk '/:8008/root/ {printf $3 "\t"}' $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
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\t", gensub(/ajpv12://(.*):8008/root/, "\1", 1, $3) } END { printf "\n" }'
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\t", gensub(/\w+://(.*):[[:digit:]]+/root/, "\1", 1, $3) } END { printf "\n" }'
takes input: foo bar URL baz
output: URL\tURL\tURL\n
-- Fridh
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