bugGNU Parallel - Bugs: bug #64819, Regexp capture groups

 
 

bug #64819: Regexp capture groups

Submitter:  None
Submitted:  Thu 26 Oct 2023 03:11:22 PM UTC
   
 
Category:  None Severity:  3 - Normal
Item Group:  None Status:  None
Privacy:  Public Assigned to:  None
Open/Closed:  Open
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 30 Oct 2023 12:17:39 PM UTC, comment #4: 

It is probably harder to implement named capture groups:

    --match -(?<foo>..)/(?<bar>...) -a file1
    --match -(?<baz>.),(?<quux>.) -a file2
    echo {foo} {baz}


Anonymous
Mon 30 Oct 2023 11:00:14 AM UTC, comment #3: 

Notation could be: {n.m} where n is the input source and m is the capture group.

    --match -(..)/(...) -a file1
    --match -(.),(.) -a file2
    echo {2.2} {1.1}

With '--header 0':

    --match -(..)/(...) -a file1
    --match -(.),(.) -a file2
    echo {file2.2} {file1.1}

Anonymous
Mon 30 Oct 2023 10:57:07 AM UTC, comment #2: 

Each --match is linked to a file. This can visually be expressed by using -a instead of :::: :

    --match ...1 -a file1
    --match ...2 -a file2

To support ::::+ in -a we introduce --a+ which is -a but acts like ::::+ Can we do this in Perl's parsing of options? or would it be OK if the filename is magic: +file means treat it as ::::+

If you have 3 files and you want to match file1 and file3 but not file2:

    --match ...1 -a file1
    --match ''   -a file2
    --match ...2 -a file2

To refer to a previous match use +n:

    --match ''   -a file1
    --match ...2 -a file2
    --match +2   -a file3 # Same regexp as second --match

Lines that do not match the regexp should not be run, but reported with a warning: If you know there is a single line, it should not die. But you also want to know if a line does not match.

Anonymous
Mon 30 Oct 2023 12:33:39 AM UTC, comment #1: 

It is not only useful for tables:

    $ parallel --match '(.*)\.(.*)' mv {} {1}.csv ::: *.txt                                      

Single --match is for all input sources.

Multiple --match is for each input source.

It should work similar to colsep except {} is unchanged.





Ole Tange <tange>
Group administrator
Thu 26 Oct 2023 03:11:22 PM UTC, original submission:  

See https://github.com/aaronriekenberg/rust-parallel/wiki/Manual#regular-expression

This can be done using multiple some repeating

  {=1 /(...),(...),(...)/; $_=$1 =}
  {=1 /(...),(...),(...)/; $_=$2 =}
  {=1 /(...),(...),(...)/; $_=$3 =}

but it would be nicer to simply give the regexp to match, so $ARG[2] = $2 after matching.

Maybe part of --colsep? Maybe --colmatch?

  --colmatch '(.*),((.*),(.*))' echo {1} {2} {3} {4}
  --colmatch '(?<foo>.*),(?<barbaz>(?<bar>.*),(?<baz>.*))' echo {foo} {barbaz} {bar} {baz}

Small issue: {foo} is normally converted into {1}, how can we use $+{foo} as {foo}?

Can we simply replace into the template:

    #!/usr/bin/perl

    $t = '{foo} {barbaz}';
    @a = ("a,b,c",
          "o,,car");

    for(@a) {
        /(.*),((.*),(.*))/ or die;
        print "$1 - $2 - $3 - $4\n";
        /(?<foo>.*),(?<barbaz>(?<bar>.*),(?<baz>.*))/ or die;
        %a = %+;
        print "$+{foo} - $+{barbaz} - $+{bar} - $+{baz}\n";
        $re ||= '\{('. join('|',keys %+).')\}';
        $tt = $t;
        $tt =~ s/$re/$a{$1}/ego;
        print $tt,"\n";
    }


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.

     

    No changes have been made to this item

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code