perl - extract every nth number -


i want extract every 3rd number ( 42.034 , 41.630 , 40.158 on ) file see example-

42.034  13.749  28.463  41.630  12.627  28.412  40.158  12.173  30.831  26.823 12.596  32.191  26.366  13.332  32.938  25.289  12.810  32.419  23.949  13.329 

any suggestions using perl script ?

thanks, dac

you can split file's contents separate numbers , use modulo operator extract every 3rd number:

my $contents = { local $/; open $fh, "file" or die $!; <$fh> };     @numbers = split /\s+/, $contents;  (0..$#numbers) {     $_ % 3 == 0 , print "$numbers[$_]\n"; } 

Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -