bugGNU Parallel - Bugs: bug #66042, Idea: printf formatting of values

 
 

bug #66042: Idea: printf formatting of values

Submitter:  None
Submitted:  Mon 29 Jul 2024 03:07:13 PM UTC
   
 
Category:  None Severity:  3 - Normal
Item Group:  None Status:  Fixed
Privacy:  Public Assigned to:  None
Open/Closed:  Closed
* Mandatory Fields

Add a New Comment Rich Markup
   

Sun 29 Sep 2024 06:21:42 PM UTC, comment #1: 

Implemented in 20240822.

Ole Tange <tange>
Group administrator
Mon 29 Jul 2024 03:07:13 PM UTC, original submission:  

Python uses {variablename:formatting} to format strings:
https://docs.python.org/3/library/string.html#formatspec

The formatting is inspired by printf, but not 100% printf syntax.

Use python's : to separate the formatting:

  {1:%010.2f} => $_=$ARG[1]; printf("%010.2f",$_)
  {:% 10s}    => printf("% 10s",$_)
  {=2 $_/=2; :% 10s=}  => $_=$ARG[2]; $_/=2; printf("% 10s",$_)
  {namedvar:%8.2f} => {4:%8.2f} => $_=$ARG[4]; printf("%8.2f",$_)

Potential problem:

  {=s:a:b:g=} :g is not a formatting instruction.

Solved by forcing :% to be the start for printf formatting.

So this will work:

   {:%d pct} => printf("%d pct",$_)

But this will not:

   {:pct=%d} => printf("pct=%d",$_)

because :pct does not start with :% and thus cannot reliably be detected from perl's s::: function.

--plus defines {:num} inspired from bash. num can be an negative and positive integer. But it can never start with :%, so it will be unabiguous whether you use printf syntax or bash.

We cannot use % by itself, because --plus defines {%regexp}.

Benefit: If you need values to be formatted as %04d, it is now easy:

    parallel echo {:%04d} ::: 12.34 123.4 1234

It can be used on all replacement strings.

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by tange (Posted a comment)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2024-09-29 tange StatusNone Fixed
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-8ccc.
    Corresponding source code