{"id":13437112,"url":"https://github.com/lotabout/rargs","last_synced_at":"2025-04-12T03:53:01.417Z","repository":{"id":40990877,"uuid":"128610722","full_name":"lotabout/rargs","owner":"lotabout","description":"xargs + awk with pattern matching support. `ls *.bak | rargs -p '(.*)\\.bak' mv {0} {1}`","archived":false,"fork":false,"pushed_at":"2023-07-30T08:34:10.000Z","size":57,"stargazers_count":522,"open_issues_count":12,"forks_count":20,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-04-12T03:52:54.718Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lotabout.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2018-04-08T07:12:00.000Z","updated_at":"2025-04-07T09:12:54.000Z","dependencies_parsed_at":"2022-07-09T06:46:23.426Z","dependency_job_id":"bc5b4a46-1d5f-4d6c-ab32-1a15b8c7a36f","html_url":"https://github.com/lotabout/rargs","commit_stats":{"total_commits":42,"total_committers":5,"mean_commits":8.4,"dds":0.09523809523809523,"last_synced_commit":"cdeedcc0a99e2ac88a572d7f58ae6bd31d037a8d"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lotabout%2Frargs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lotabout%2Frargs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lotabout%2Frargs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lotabout%2Frargs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lotabout","download_url":"https://codeload.github.com/lotabout/rargs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248514209,"owners_count":21116899,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T03:00:54.406Z","updated_at":"2025-04-12T03:53:01.398Z","avatar_url":"https://github.com/lotabout.png","language":"Rust","readme":"**Rargs** is kind of `xargs` + `awk` with pattern-matching support.\n\n[![Crates.io](https://img.shields.io/crates/v/rargs.svg)](https://crates.io/crates/rargs) [![Build Status](https://travis-ci.org/lotabout/rargs.svg?branch=master)](https://travis-ci.org/lotabout/rargs)\n\n## Installation\n\n### Mac OS\n\n```\nbrew install rargs\n```\n\n### Nix\n\n```\nnix-env -i rargs\n```\n(Currently available in unstable channel)\n\n### Binary\n\nDownload in the [Release Page](https://github.com/lotabout/rargs/releases) and\nput it in your `PATH` after uncompress.\n\n### Using Cargo\n\n```\ncargo install --git https://github.com/lotabout/rargs.git\n```\n\n## Example usage\n\n### Batch rename files\n\nSuppose you have several backup files whose names match the pattern `\u003cscriptname\u003e.sh.bak`, and you want to map each filename back to `\u003cscriptname\u003e.sh`. We want to do it in a batch, so `xargs` is a natural choice, but how do we specify the name for each file? I believe there is no easy way.\n\nWith `rargs`, however, you are able to do:\n\n```sh\nls *.bak | rargs -p '(.*)\\.bak' mv {0} {1}\n```\n\nHere `{0}` refers to the whole input line, while `{1}` refers to the first group captured in the regular expression.\n\n### Batch download\n\nI had a bunch of URLs and their corresponding target filenames stored in a CSV file:\n\n```\nURL1,filename1\nURL2,filename2\n```\n\nI hoped there was a simple way to download and save each URL with its specified filename. With `rargs` there is:\n\n```sh\ncat download-list.csv | rargs -p '(?P\u003curl\u003e.*),(?P\u003cfilename\u003e.*)' wget {url} -O {filename}\n```\n\nHere `(?P\u003cgroup_name\u003e...)` assigns the name `group_name` to the captured group. This can then be referred to as `{group_name}` in the command.\n\n### AWK replacement?\n\nSuppose you have an xSV file with lots of columns, and you only want to extract and format some of them, e.g.:\n\n```\nnobody:*:-2:-2:Unprivileged User:/var/empty:/usr/bin/false\nroot:*:0:0:System Administrator:/var/root:/bin/sh\ndaemon:*:1:1:System Services:/var/root:/usr/bin/false\n```\n\nHere's an example of how `rargs` can be used to process it:\n\n```\n$ cat /etc/passwd | rargs -d: echo -e 'id: \"{1}\"\\t name: \"{5}\"\\t rest: \"{6..::}\"'\nid: \"nobody\"     name: \"Unprivileged User\"       rest: \"/var/empty:/usr/bin/false\"\nid: \"root\"       name: \"System Administrator\"    rest: \"/var/root:/bin/sh\"\nid: \"daemon\"     name: \"System Services\"         rest: \"/var/root:/usr/bin/false\"\n```\n\n`rargs` allow you to specify the delimiter (regex) to split the input on, and allows you to refer to the corresponding fields or field ranges. This allows it to be used as an AWK replacement for some simple but common cases.\n\n## How does it work?\n\n1. receive the input on stdin and split it into lines\n2. split (`-d`) or extract (`-p`) the input into named or numbered groups, with `{0}` matching the whole line\n3. map the named and numbered groups into a command passed as the remaining arguments, and execute the command\n\n## Features\n\n### Regexp captures\n\n`rargs` allows you to use any regular expression to match the input, and captures anything you are interested in. The syntax is the standard, mostly Perl-compatible [Rust regex syntax](https://docs.rs/regex/0.2.10/regex/#syntax) used by tools such as [ripgrep](https://github.com/BurntSushi/ripgrep).\n- positional (numbered) groups are captured with parentheses, e.g. `'(\\w+):(\\d+)'`, and the corresponding groups are referred to by `{1}`, `{2}` etc. in the command\n- named groups are captured with `(?P\u003cname\u003e...)` and referred to by `{name}` in the command\n\n### Delimiter captures\n\nFor simple usage, you might not want to write the whole regular expression to extract parts of the line. All you want is to split the groups by some delimiter. With `rargs` you can achieve this by using the `-d` (delimiter) option.\n\n### Field ranges\n\nWe already know how to refer to captures by number (`{1}`) or by name (`{name}`). There are also cases where you might want to substitute multiple fields at the same time. `rargs` also supports this with field-range expressions.\n\nSuppose we have already captured 5 groups representing the strings `1`, `2`, `3`, `4` and `5`\n\n- `{..}` gathers them all into `1 2 3 4 5` (note that they are separated by a space; this can be overridden by the `-s` option)\n- `{..3}` results in `1 2 3`\n- `{4..}` results in `4 5`\n- `{2..4}` results in `2 3 4`\n- `{3..3}` results in `3`\n\nYou can also specify a \"local\" separator (which will not affect the global setting):\n\n- `{..3:-}` results in `1-2-3`\n- `{..3:/}` results in `1/2/3`\n\n### Negative field\n\nSometimes you may want to refer to the last few fields but have no way to predict the total number of fields of the input. `rargs` offer negative fields.\n\nSuppose we have already captured 5 groups representing the strings `1`, `2`, `3`, `4` and `5`:\n\n- `{-1}` results in `5`\n- `{-5}` results in `1`\n- `{-6}` results in nothing\n- `{-3..}` results in `3 4 5`\n\n### Multiple threading\n\nYou can run commands in multiple threads to improve performance:\n\n- `-w \u003cnum\u003e` specifies the number of workers you want to run simultaneously\n- `-w 0` defaults the number of workers to the number of CPUs on your system\n\n### Special Variables\n\n- `{LINENUM}` or `{LN}` to refer to current line number.\n\n## Interested?\n\nAll feedback and PRs are welcome!\n","funding_links":[],"categories":["Applications","Rust","应用程序 Applications","Other","应用","应用 Applications","others","Shell/Terminal","Xargs-like Tools"],"sub_categories":["System tools","系统工具 System tools","系统工具","Open USP Tsukubai"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flotabout%2Frargs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flotabout%2Frargs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flotabout%2Frargs/lists"}