- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - OpenVMS
- >
- Re: Extracting a specific string
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
тАО11-17-2010 07:12 AM
тАО11-17-2010 07:12 AM
Extracting a specific string
I'm looking to extract and specific string from a file. Basically, first I execute a ping to a host (before will be 20) that the result go to a file.
Then, a job try to search what % of packets have lost. Well, with the lexical F$EXTRACT and F$LOCATE I can only print "0% packet loss" but putting a lot of condicionals, and I don't like much this metod. How could I extract only the 0% (or 100%)? With this value
Thanks and regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-17-2010 07:30 AM
тАО11-17-2010 07:30 AM
Re: Extracting a specific string
Dan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-17-2010 07:40 AM
тАО11-17-2010 07:40 AM
Re: Extracting a specific string
"4 packets transmitted, 4 packets received, 0% packet loss"
Then parse it like:
line=f$edit(line,"TRIM,COMPRESS")
rest=f$edit(f$element(2,",",line),"TRIM")
perc=f$element(0," ",rest)
show sym perc
I broke it into several stements for clarity, You can put everything into a single f$element(...) statement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-17-2010 08:04 AM
тАО11-17-2010 08:04 AM
Re: Extracting a specific string
http://www.ping127001.com/pingpage.htm
http://www.cs.utah.edu/~swalton/listings/sockets/programs/part4/chap18/ping.c
There's a callable ping tool on Freeware V8.0.
There are also free and commercial services around such as the pingdom service, and any number of monitoring tools such as nagios nrpe that can be used to monitor uptime.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-17-2010 08:07 AM
тАО11-17-2010 08:07 AM
Re: Extracting a specific string
A lot of thanks Joseph and abrsvc. I have exactly that i wanted
$ OPEN IN OPER00DIR:PING.DAT
$ LOOP:
$ READ/END_OF_FILE=ENDIT IN NAME
$ HOST = F$EXTRACT(F$LOCATE("4 packets",NAME),100 ,NAME)
$ HOST=f$edit(HOST,"TRIM,COMPRESS")
$ rest=f$edit(f$element(2,",",HOST),"TRIM")
$ perc=f$element(0," ",rest)
$ IF HOST .EQS. ""
$ THEN
$ GOTO LOOP
$ ELSE
$ SHOW SYMBOL PERC
$ ENDIF
$ ENDIT:
$ CLOSE IN
Now, with this value can use it to know wicht devices are working, etc and a new syntaix for future
Thanks againt for your help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-17-2010 08:08 AM
тАО11-17-2010 08:08 AM
Re: Extracting a specific string
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-17-2010 08:56 AM
тАО11-17-2010 08:56 AM
Re: Extracting a specific string
You may want to take a step back and look at the larger problem you are trying to solve.
What are you going to do next with that PERC symbol value?
I can parse text files with DCL with the best of them, and even enjoy doing that (yeah, twisted person), but sometimes there are better tools.
For just playing around with strings I find PERL and AWK very convenient.
Here, for example to just get that specific string:
perl -ne "print $1 if /(\d+)% packet loss/" tmp.tmp
Want to add the host name to that?
perl -ne "$host=$1 if /^----(\S+)\s+PING/; print qq($host $1) if /(\d+)% packet loss/" tmp.tmp
Enjoy!
Hein
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-18-2010 12:35 AM
тАО11-18-2010 12:35 AM
Re: Extracting a specific string
The objetive of this job is know which terminal are in use after working hour. So I need a value to know if the terminal is switched-on. My first idea was make a ping. If don't response, then the Thinclient are swiched-off.
Of course, I can use a Nagios system to monitor if a terminals are swhitched-on or not. But I think that this way is more interesting to learn and gain experience (I'm new in this environment)
Thanks and regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-18-2010 06:03 AM
тАО11-18-2010 06:03 AM
Re: Extracting a specific string
fwiw,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-18-2010 06:16 AM
тАО11-18-2010 06:16 AM
Re: Extracting a specific string
I'd even use C here (with any of the available ping libraries) long before I'd try using DCL, too. DCL is an increasingly poor choice.
That written, it would not surprise me to learn that this problem has already been solved. Dozens of times. Why even write code if you don't need to?