- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Sort by port range
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-22-2011 01:35 PM
тАО07-22-2011 01:35 PM
Sort by port range
Hi All,JRF
Have the following command and its output -
/usr/bin/curl http://URL |grep VIP |awk '{print $1,$3}'|/usr/bin/perl -lne 'm{"(.*?)".*?//(.*):(\d+)/} and print "$2 $3"'|sort -u -k2,2
VIP 2001
VIP 3001
VIP 4001
VIP 4233
VIP 3002
VIP 2020
тАж..
Need to have an output in a way so that I get only 2xxx port series or 3xxxx or 4xxxx and not all. Can we trim the output in this fashion?
Desired output can be (if sorting by ports of 2xxx series only) -
VIP 2001
VIP 2020
...
Thanks,
Allan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-22-2011 02:16 PM
тАО07-22-2011 02:16 PM
Re: Sort by port range
>Can we trim the output in this fashion?
You have several places in your pipeline where you can do that:
awk '/VIP/ && substr($3, 1,1) == 2 {print $1,$3}' | perl -lne 'm{"(.*?)".*?//(.*):(\d+)/} and print "$2 $3"' | sort -u -k2,2
Though I'm not quite sure what that perl script does.
Nor why you have both perl and awk (and grep) in the same pipeline. Aren't you afraid they might start a fight? :smileytongue:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-22-2011 02:57 PM
тАО07-22-2011 02:57 PM
Re: Sort by port range
Hi Allan:
Dennis is right --- this is awful mixing Perl and 'awk' in a pipeline. I vaguely remember a post (or two) of yours where I suggested the regular expression for matching, but that's about all.
It would be nice if you posted your *raw* input and then what you would like it distilled into!
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-25-2011 01:53 PM
тАО07-25-2011 01:53 PM
Re: Sort by port range
Hi JRF,Dennis,
Here is the raw and distilled outputs -
Raw Output - "AccountService" = "http://foobar.com:2000/cgi-bin/JBOSS/app/acct"; "StaticApp" = "http://foobar.com:4001/service/content"; "ContentApp" = "http://foobar.com:3005/cgi-bin/JBOSS/App.jbs/content";
desired output 1 - foobar.com 2000 foobar.com 4001 foobar.com 3005 desired output 2 - AccountService foobar.com 2000 StaticApp foobar.com 4001 ContentApp foobar.com 3005
Thanks,
Allan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-25-2011 02:34 PM
тАО07-25-2011 02:34 PM
Re: Sort by port range
Hi (again):
Well, long time, no hear :-)
Anyway:
# perl -lne 'm{"(.*?)".*?//(.*):(\d+)/} and print "$2 $3"' FILE |sort -u -k2,2 or (of course, in a pipeline): # ... | perl -lne 'm{"(.*?)".*?//(.*):(\d+)/} and print "$2 $3"' | sort -u -k2,2
gives:
foobar.com 2000
foobar.com 4001
foobar.com 3005
AND:
# perl -lne 'm{"(.*?)".*?//(.*):(\d+)/} and print "$1 $2 $3"' FILE (or): # ... | perl -lne 'm{"(.*?)".*?//(.*):(\d+)/} and print "$1 $2 $3"'
yields:
AccountService foobar.com 2000
StaticApp foobar.com 4001
ContentApp foobar.com 3005
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-26-2011 05:09 AM
тАО07-26-2011 05:09 AM
Re: Sort by port range
Do you still want to limit the output to one of the 2xxx, 3xxx or 4xxx series?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-26-2011 05:45 AM
тАО07-26-2011 05:45 AM
Re: Sort by port range
Hi (again):
Oops, there's at least one correction that should be made. Since the port numbers are numeric we need to tell the sort that:
# ... | perl -lne 'm{"(.*?)".*?//(.*):(\d+)/} and print "$2 $3"' | sort -nk2,2
# ... | perl -lne 'm{"(.*?)".*?//(.*):(\d+)/} and print "$1 $2 $3"' | sort -nk3,3
Notice that I dropped the '-u' sort option. It's not clear why (we) used that. If want to restrict the output to some range of port numbers as this post suggestes, do:
# ... | perl -lne 'm{"(.*?)".*?//(.*):(\d+)/} && $3>=2000 && $3<=2999 and print "$2 $3"' or: # ...| perl -lne 'm{"(.*?)".*?//(.*):(\d+)/} && $3>=2000 && $3<=2999 and print "$1 $2 $3"'
...depending on the output format for which you asked. You can pipe those results to 'sort -nk2,2' or 'sort -nk3,3' respectively to order the output by ascending port number.
...JRF...