Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: sfeam Newsgroups: comp.graphics.apps.gnuplot Subject: Re: How to know total number of blocks in a file? Followup-To: comp.graphics.apps.gnuplot Date: Thu, 15 Mar 2012 09:53:04 -0700 Organization: gnuplot development team Lines: 42 Message-ID: References: <5661512.256.1331822623825.JavaMail.geo-discussion-forums@ynhs12> Reply-To: sfeam@users.sourceforge.net Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit Injection-Date: Thu, 15 Mar 2012 16:53:07 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="3mhAfh4CeAIeL3OKnPexDA"; logging-data="26480"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX180eanwfxmC+6JbPOnSc/NO" User-Agent: KNode/4.4.9 Cancel-Lock: sha1:ULr0Xxq8pGWkmegMptk/0qo9bEA= Xref: csiph.com comp.graphics.apps.gnuplot:977 ampbox@gmail.com wrote: > Hi all, > > I have a data file with multiple data blocks (groups of data lines > separated by blank lines). I want to plot only the last block. > > I can do it like > > plot 'filename' every ::::: > > where is the block number, and since it is the last block, > this number equals the total number of blocks in my data file. > > The problem is, I don't know how many blocks are there in my data > file. (Because my simulation adds a new block every few hours and the > longer simulation runs, the more number of frames (block) I get.) > > Is there a built-in variable like GPVAL_DATA_X_MAX etc. to give me > this information? Not currently. There is a contributed patch on the SourceForge tracker that claims to add something like this (I haven't looked at it so I don't know the details). > Another possible solution: can I get the number of lines etc. by a > bash command (I am in Linux) INSIDE my gnuplot script and give it to a > variable? I mean something like: > > NBLOCKS = `!wc -l filename` Sure. But wc unfortunately returns a line that contains also the filename. So you need: WC = `wc -l filename` NBLOCKS = word(WC,1) > > Thanks in advance, > Masoud.