Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Expect to parse file. 1

Status
Not open for further replies.

NetworkGhost

IS-IT--Management
Apr 12, 2005
1,324
US
I have a SSH script that runs pings on a router every 15 minutes and send the output to a file. What I want to do is parse the file so it can later be opened in excel.

The output line looks like so:

Success rate is 100 percent (5/5), round-trip min/avg/max = 92/95/108 ms

What I want to do is make it look like:

(5/5) 92 95 108

Can expect do this? Would SED or something else do better? Does anyone have any good examples of how I can start this?


Free Firewall/Network/Systems Support-
 
This seems like a good application for regexp
Code:
%set s "Success rate is 100 percent (5/5), round-trip min/avg/max = 92/95/108 m
s"
regexp {.*(\(\d*/\d*\)).* = (\d*)/(\d*)/(\d*).*} $s a b c d e
now:
% set b
(5/5)
% set c
92
% set d
95
% set e
108

_________________
Bob Rashkin
 
I dont have regexp available on my server. Cant install anything new. I have expect, perl, ksh, bash, sed and awk. My have more but dont know.

Free Firewall/Network/Systems Support-
 
I don't know much about Expect, other than that it's an extention of Tcl. I thought that meant it could understand Tcl statements. Not so? (regexp is a regular Tcl statement).

_________________
Bob Rashkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top