groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Use of sed in PDFPIC macro with OpenBSD


From: Andreas Kusalananda Kähäri
Subject: Re: Use of sed in PDFPIC macro with OpenBSD
Date: Tue, 7 Dec 2021 22:46:22 +0100

On Tue, Dec 07, 2021 at 06:49:11PM +0100, Hans Bezemer wrote:
> Hi Ralph,
> 
> >     > awk '/^Page size:/ {print ".nr pdf-wid (p;"$3")"; print ".nr pdf-ht  
> > (p;"$5")"}'
> >     .nr pdf-wid (p;595)
> >     .nr pdf-ht  (p;842)
> >     $
> Thanks, this helped.
> Changed the appropriate lines into:
> .  sy pdfinfo @$1 | \
> awk '/^Page size:/ {print ".nr pdf-wid (p;"$3")"; \
> print ".nr pdf-ht  (p;"$5")"}' \
> > /tmp/pdfpic\n[$$]
> 
> This seems to work fine.
> I've attached a patch file.
> 
> 
> 
> Kind regards,
> 
> Hans

> --- pdfpic.tmac.origin        Tue Dec  7 18:28:07 2021
> +++ pdfpic.tmac       Tue Dec  7 18:34:15 2021
> @@ -84,10 +84,8 @@
>  .\" get image dimensions
>  .  ec @
>  .  sy pdfinfo @$1 | \
> -grep "Page *size" | \
> -sed -e 's/Page *size: *\\([[:digit:].]*\\) *x *\\([[:digit:].]*\\).*$/\
> -.nr pdf-wid (p;\\1)\\n\

Yeah, standard (well, BSD in this case, at least OpenBSD and macOS)
sed can't be expected to be able to insert a newline using "\n" in the
replacement text of the s/// command (that's a GNU sed extension).  You
would have to use an escaped literal newline instead.  Looking at the
code above, it seems as removing the "n" of "\n" would be enough as it
leaves "\\\" at the end of the line.  I haven't tested that.


> -.nr pdf-ht  (p;\\2)/' \
> +awk '/^Page size:/ {print ".nr pdf-wid (p;"$3")"; \

I'm noting that the original regular expression allows for zero or more
spaces between "Page" and "size", and also accepts zero or more spaces
after the "size:" substring.  The awk code can't allow no spaces, as it
would offset the field numbering.  I don't know if this is an issue or
not.

> +print ".nr pdf-ht  (p;"$5")"}' \
>  > /tmp/pdfpic\n[$$]
>  .  so /tmp/pdfpic\n[$$]
>  .  sy rm /tmp/pdfpic\n[$$]


-- 
Andreas (Kusalananda) Kähäri
SciLifeLab, NBIS, ICM
Uppsala University, Sweden

.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]