in reply to Command Parsing
You can use a 'while' loop to read your output file you have generated, from the CLI, then use a regex to pick out the values you are want like this:
use warnings; use strict; while (<>) { chomp; if (m/(.+?)\s+?=\s+?(\d+?).?$/) { print $1, " : ", $2, $/; } }
Or you could decide to pipe in your command in your script, then *work on* each of the line as you want like this: Just run your script i.e >my_script.pl
#!/usr/bin/perl use warnings; use strict; open my $fh,'-|', q[xgridstatus -h localhost -A] or die "can open this + file: $!"; while (<$fh>) { chomp; if (m/(.+?)\s+?=\s+?(\d+?).?$/) { print $1, " : ", $2, $/; } } close $fh or die "can't close this file:$!";
Hope it helps
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Command Parsing
by jcstech (Initiate) on Apr 25, 2012 at 13:50 UTC | |
by 2teez (Vicar) on Apr 25, 2012 at 17:43 UTC |