#!/usr/bin/perl use strict; use warnings; my $cmd = "/usr/sbin/ntpq -p"; my @ntpout = grep (/^\*/, `$cmd`); # grep line starting with * sign and put into an array my $file = 'offset.txt'; open (my $fh, '>' $file) or die "Could not open file '$file' $!"; print $fh "@ntpout\n"> close $fh; # Written array output into file my $offset = `cat offset.txt | awk '{print $9}'`; # here expecting 9th cloumn value in variable $offset print "$offset \n"; #### remote refid st t when poll reach delay offset disp ============================================================================== LOCAL(0) LOCAL(0) 10 l 34 64 377 0.00 0.000 10.01 *gpstime.domain.l .PPS. 1 u 879 1024 377 1.85 -0.025 0.03 hitman.domain.lo 0.0.0.0 16 - - 1024 0 0.00 0.000 16000.0