{"id":26883693,"url":"https://github.com/jiro4989/suln","last_synced_at":"2025-05-08T17:09:39.649Z","repository":{"id":60646880,"uuid":"543591401","full_name":"jiro4989/suln","owner":"jiro4989","description":"suln is a CLI that prints surroundings of line number with grep.","archived":false,"fork":false,"pushed_at":"2022-10-20T22:52:37.000Z","size":96,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-31T17:50:34.845Z","etag":null,"topics":["cli","grep","oneliner","rust","util"],"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/jiro4989.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}},"created_at":"2022-09-30T12:32:21.000Z","updated_at":"2022-10-03T14:03:27.000Z","dependencies_parsed_at":"2022-10-02T16:00:26.201Z","dependency_job_id":null,"html_url":"https://github.com/jiro4989/suln","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jiro4989%2Fsuln","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jiro4989%2Fsuln/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jiro4989%2Fsuln/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jiro4989%2Fsuln/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jiro4989","download_url":"https://codeload.github.com/jiro4989/suln/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253112071,"owners_count":21856070,"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":["cli","grep","oneliner","rust","util"],"created_at":"2025-03-31T17:36:48.032Z","updated_at":"2025-05-08T17:09:38.775Z","avatar_url":"https://github.com/jiro4989.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# suln\n\n`suln` is a CLI that prints surroundings of line number with `grep`.\n\n![demo](./docs/demo.png)\n\n## Usage\n\nBasic usage is:\n\n```bash\ngrep -nH '\u003cpattern\u003e' '\u003cfile\u003e' | suln \u003c-B NUM | -A NUM | -C NUM\u003e\n```\n\n`suln` use file name and line number with `grep`.\nAnd `suln` provides you with continuation of `grep` .\n\nFor example, simply grep to search with file name and line number.\n\n```bash\n$ grep -Hn Usage README.adoc\nREADME.adoc:7:== Usage\n```\n\nAnd, add `suln -A` (`--after-context`).\n`suln` outputs the continuation of an interrupted search result.\n\n```bash\n$ grep -Hn Usage README.adoc | suln -A 2\nREADME.adoc:7:== Usage\nREADME.adoc:8:\nREADME.adoc:9:Basic usage is:\n```\n\nUse `-B` (`--before-context`) if you want to search before text.\n\n```bash\n$ grep -Hn Usage README.adoc | suln -B 2\nREADME.adoc:5:`suln` is a CLI that prints surroundings of line number with `grep`.\nREADME.adoc:6:\nREADME.adoc:7:== Usage\n```\n\nUse `-C` (`--context`) if you want to search before or after text.\n\n```bash\n$ grep -Hn Usage README.adoc | suln -C 2\nREADME.adoc:5:`suln` is a CLI that prints surroundings of line number with `grep`.\nREADME.adoc:6:\nREADME.adoc:7:== Usage\nREADME.adoc:8:\nREADME.adoc:9:Basic usage is:\n```\n\nThese options are same `grep`.\n\n```bash\n$ grep --help | grep -Eo '(-[ABC].+=NUM)'\n-B, --before-context=NUM\n-A, --after-context=NUM\n-C, --context=NUM\n```\n\n### Usecase: searching JSON data\n\nHere is an example of AND search for multiple keys in JSON.\nSearches for `id` where `name` is `bob` and `age` is `18`.\nThis is not possible with `grep` alone.\n\n```bash\n$ grep -C 2 bob testdata/example.json\n  {\n    \"id\": 31,\n    \"name\": \"bob\",\n    \"age\": 18\n  },\n--\n  {\n    \"id\": 334,\n    \"name\": \"bob\",\n    \"age\": 4\n  },\n```\n\nBecause, `id` is disappear when search with `age`.\n\n```bash\n$ grep -HnC 2 bob testdata/example.json | grep 'age.*18'\n    \"age\": 18\n```\n\nYou must use many commands if you want to get `id`.\n\n```bash\n$ grep -C 2 bob testdata/example.json | grep -Ev '^--$' | paste - - - - - | grep 'bob.*age.*18' | grep -Eo '\"id[^,]+' '\"'  | awk '{print $2}'\n31\n```\n\nOr, you must write complexity `jq` query.\n\n```bash\n⟩ jq -r '.[] | select(.name == \"bob\" and .age == 18) | .id' testdata/example.json\n31\n```\n\n`suln` is useful if you would like to search more intuitive.\n\n```bash\n$ grep -HnC 2 bob testdata/example.json | grep 'age.*18'\ntestdata/example.json-15-    \"age\": 18\n\n$ grep -HnC 2 bob testdata/example.json | grep 'age.*18' | suln -B 2\ntestdata/example.json:13:    \"id\": 31,\ntestdata/example.json:14:    \"name\": \"bob\",\ntestdata/example.json:15:    \"age\": 18\n\n⟩ grep -HnC 2 bob testdata/example.json | grep 'age.*18' | suln -B 2 | grep 'id.*31'\ntestdata/example.json:13:    \"id\": 31,\n```\n\n## Installation\n\n```bash\n$ cargo install suln\n```\n\nOr, you can download and install from [GitHub Releases](https://github.com/jiro4989/suln/releases).\n\n## LICENSE\n\nMIT\n\n## For developer\n\n### Pre-requisite\n\n* rustc 1.64.0 (a55dd71d5 2022-09-19)\n\n### Build\n\n```bash\ncargo build\n```\n\n### Test\n\n```bash\ncargo test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjiro4989%2Fsuln","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjiro4989%2Fsuln","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjiro4989%2Fsuln/lists"}