[gradsusr] count number of files, interact with shell,
Becker, Bernd
bernd.becker at metoffice.gov.uk
Tue Aug 23 11:10:10 EDT 2011
* dear grads user,
* how can I get the number of files with the extension .gs
* into the local grads variable nfiles?
* got it now; closing the file to rewind it helps a lot. Yet:
'@ !ls -l *.gs | wc -l'
res=sublin(result,2)
nfiles= subwrd(res,1)
say 'nfiles= ' nfiles
'@ !export nfiles=`ls -l *.gs | wc -l`'
'getenv nfiles'
nfiles=subwrd(result,5)
say 'nfiles= ' nfiles
'@ !ls -l *.gs | wc -l > ./erp$$'
say result
filename = subwrd(result,8)
say 'filename = ' filename
record2 = read (filename)
say record2
nfiles = sublin(record2,2)
say 'nfiles= ' nfiles
say ' '
say ' fine! but in a loop:'
say ' '
pop =1
while ( pop < 5)
'@ !ls -l *.gs | wc -l > ./erp$$'
say result
filename = subwrd(result,8)
say 'filename = ' filename
record2 = read (filename)
say record2
nfiles = sublin(record2,2)
say 'nfiles= ' nfiles
* close the file to rewind it!
close( filename)
pop =pop +1
endwhile
say " is there no better way to do this sort of thing?"
* thanks for all your help.
* Bernd.
--
Bernd Becker Climate Impacts Product Development
Met Office Hadley Centre FitzRoy Road Exeter Devon EX1 3PB United
Kingdom
Tel.: +44 (0) 1392 884511 Fax: +44 (0)870 900 5050
E-mail:bernd.becker at metoffice.gov.uk -
http://www.metoffice.gov.uk/research/our-scientists/seasonal-to-decadal/
bernd-becker
http://www.metoffice.gov.uk/news/releases/archive/2011/weather-game
More information about the gradsusr
mailing list