- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Help parsing file
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
Forums
Discussions
Discussions
Discussions
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
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-30-2004 06:41 AM
07-30-2004 06:41 AM
Help parsing file
Interesting ports on mke1qdhe06.corp.fortishealth.com (165.245.247.239)
(The 1650 ports scanned but not shown below are in state: closed)
PORT STATE SERVICE
135/tcp open msrpc
139/tcp open netbios-ssn
445/tcp open microsoft-ds
1027/tcp open IIS
1494/tcp open citrix-ica
3372/tcp open msdtc
3389/tcp open ms-term-serv
8080/tcp open http-proxy
8081/tcp open blackice-icecap
Device type: general purpose
Running: Microsoft Windows 95/98/ME|NT/2K/XP OS
details: Microsoft Windows Millennium Edition (Me), Windows 2000 Pro
Each machine has a block like this. I need to parse out the IP address of the server, but only if it is a Windows server.
Any ideas?
TIA and points for all responses.
Sean
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2004 06:53 AM
07-30-2004 06:53 AM
Re: Help parsing file
Here's an idea from "Handy One-Liners for Sed" (attached).
# print 1 line of context before and after regexp, with line number
# indicating where the regexp occurred (similar to "grep -A1 -B1")
sed -n -e '/regexp/{=;x;1!p;g;$!N;p;D;}' -e h
I believe you could alter that to print the IP address line.
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2004 06:55 AM
07-30-2004 06:55 AM
Re: Help parsing file
cat file|grep "Running" |awk -F ":" '{print $2}' >> /tmp/os.txt
paste /tmp/os.txt /tmp/host.txt > /tmp/final.txt
awk -F " " '{if ($1==Microsoft) print}' /tmp/final.txt
Anil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2004 07:08 AM
07-30-2004 07:08 AM
Re: Help parsing file
How would that work since the IP line could vary in the number of lines away from the server line?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2004 07:12 AM
07-30-2004 07:12 AM
Re: Help parsing file
Sorry, I assumed that it would be consistent - if it's not, that idea won't work.
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2004 07:12 AM
07-30-2004 07:12 AM
Re: Help parsing file
perl -n -e '/^Interesting ports on (\S+)\s+(\d+\.\d+\.\d+)/ && do { $mach=$1; $ip=$2; }; /^Running.*Windows/i && do { print "$ip $mach\n";' yourinputfile.txt
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2004 09:45 AM
07-30-2004 09:45 AM
Re: Help parsing file
awk '
/^Interesting/ {mach=$4;ip=$5;next;}
/^Running/ { if ( $0 ~ "[W,w]indows" )
print $4 " " $5;}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2004 09:59 AM
07-30-2004 09:59 AM
Re: Help parsing file
i hope you caught that
/^Running/ { if ( $0 ~ "[W,w]indows" )
print $4 " " $5;}'
should have been
/^Running/ { if ( $0 ~ "[W,w]indows" )
print mach " " ip;}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2004 03:55 PM
07-30-2004 03:55 PM
Re: Help parsing file
is there anyway you can create the output file different format without the Block of fields ? How about merging into a long record with a field separator ?
how about columns separated with | instead of '\n'. I'm thinking a simple:
IFS=|
egrep -i 'running:Micro' FILE-NAME | cut -f1
record sample follows:
mke1qdhe06.corp.fortishealth.com (165.245.247.239)|(The 1650 ports scanned but not shown below are in state: closed)|PORT STATE SERVICE|135/tcp open msrpc|139/tcp open netbios-ssn|445/tcp open microsoft-ds|1027/tcp open IIS|1494/tcp open citrix-ica|3372/tcp open msdtc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2004 08:26 PM
07-30-2004 08:26 PM
Re: Help parsing file
Get the IP-Address first and check weather Running: Microsoft keyword is there or not. IF so print ip ( wiht () ) else none
awk '{ if ( $1 == "Interesting" && $2 == "ports" ) ip=$5
if ( $1 == "Running:" && $2 == "Microsoft" ) test=1 }
END { if ( test == 1) print ip }' tst.log | tr -d '()'
Your output will be ..,
165.245.247.239
Regards
Muthu