Code Comments
Programming Forum and web based access to our favorite programming groups.Hi all, I'm racking my brain the whole day long for a rather simple question. Please help me with your infinite knowledge. I want to count the number of pages in a postscript file by using the psselect-command according to psselect -p- file.ps >/dev/null Example: me@home: psselect -p- input.ps >/dev/null me@home: [1] [2] [3] [4] [5] [6] Wrote 6 pages, 603850 bytes And now, I want to extract the page number (here: 6) to process it for other things. How do I extract this number from this line? Because I want to use t he commands within a shell script and apply it generally the output line shows the page number at different positions within the line (thus 'cut' doesnt se em to work here properly). Any suggestions ? thanks, rncdnet
Post Follow-up to this messageIn article <ba35ffd8.0504110629.67f3027b@posting.google.com>,
R.K. <rncdnet@netscape.net> wrote:
>Hi all,
>
>I'm racking my brain the whole day long for a rather simple question.
>Please help me with your infinite knowledge.
>
>I want to count the number of pages in a postscript file by using the
>psselect-command according to
>
>psselect -p- file.ps >/dev/null
>
>Example: me@home: psselect -p- input.ps >/dev/null
> me@home: [1] [2] [3] [4] [5] [6] Wrote 6 pages, 603850 bytes
>
>And now, I want to extract the page number (here: 6) to process it for othe
r
>things. How do I extract this number from this line? Because I want to use
the
>commands within a shell script and apply it generally the output line shows
>the page number at different positions within the line (thus 'cut' doesnt s
eem
>to work here properly).
>Any suggestions ?
Don't use cut. cut is stupid. And this is an AWK newsgroup.
I suppose the following shell would work:
x=$(psselect -p- input.ps 2>&1 >/dev/null | gawk 'sub(/^.*Wrote */,"") {prin
t $1}')
Post Follow-up to this message
Kenny McCormack wrote:
> In article <ba35ffd8.0504110629.67f3027b@posting.google.com>,
> R.K. <rncdnet@netscape.net> wrote:
>
>
>
> Don't use cut. cut is stupid. And this is an AWK newsgroup.
>
> I suppose the following shell would work:
>
> x=$(psselect -p- input.ps 2>&1 >/dev/null | gawk 'sub(/^.*Wrote */,"") {pr
int $1}')
>
No need for sub:
x=$(psselect -p- input.ps 2>&1 >/dev/null |gawk '/Wrote/{print $(NF-3)}'
Ed.
Post Follow-up to this messageLe Mon, 11 Apr 2005 07:29:06 -0700, R.K. a écrit_:
> Hi all,
>
> I'm racking my brain the whole day long for a rather simple question.
> Please help me with your infinite knowledge.
>
> I want to count the number of pages in a postscript file by using the
> psselect-command according to
>
> psselect -p- file.ps >/dev/null
>
> Example: me@home: psselect -p- input.ps >/dev/null
> me@home: [1] [2] [3] [4] [5] [6] Wrote 6 pages, 603850 bytes
>
> And now, I want to extract the page number (here: 6) to process it for oth
er
> things. How do I extract this number from this line? Because I want to use
the
> commands within a shell script and apply it generally the output line show
s
> the page number at different positions within the line (thus 'cut' doesnt
seem
> to work here properly).
> Any suggestions ?
An overkill in fonky style but it ensures to get what's between
"Wrote" and " pages,"
$ awk 'BEGIN{RS=" pages,";FS="Wrote "};/Wrote /,/ pages,/{print $2}'
Post Follow-up to this messageIn article <KpWdnTbqr8nNDcffRVn-tg@comcast.com>,
Ed Morton <morton@lsupcaemnt.com> wrote:
...
>No need for sub:
>
>x=$(psselect -p- input.ps 2>&1 >/dev/null |gawk '/Wrote/{print $(NF-3)}'
>
> Ed.
6 of one, half dozen of the other.
Mine seems a little more generic. YMMV.
Post Follow-up to this messageIn article <ba35ffd8.0504110629.67f3027b@posting.google.com>,
R.K. <rncdnet@netscape.net> wrote:
% Please help me with your infinite knowledge.
I assume this means you want a lot of answers.
% Example: me@home: psselect -p- input.ps >/dev/null
% me@home: [1] [2] [3] [4] [5] [6] Wrote 6 pages, 603850 bytes
You could use
(psselect -p- input.ps >/dev/null) 2>&1 |
awk -F'Wrote | page' '/Wrote/ { print $2 }'
On the other hand, since psselect depends on the postscript file
following the document structuring conventions, you don't really
need to use it, just parse out the relevant DSC yourself:
awk '/^%%Pages: [0-9]+/ { print $NF; exit }' input.ps
or count all the '/^%%Page:/' entries.
--
Patrick TJ McPhee
North York Canada
ptjm@interlog.com
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.