{"id":20506584,"url":"https://github.com/mkayontour/regex_sed_awk_magix","last_synced_at":"2026-04-18T08:01:48.817Z","repository":{"id":240191670,"uuid":"117338447","full_name":"mkayontour/regex_sed_awk_magix","owner":"mkayontour","description":"Just a bunch of notes for myself","archived":false,"fork":false,"pushed_at":"2018-01-13T12:17:26.000Z","size":4,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-05T21:43:20.137Z","etag":null,"topics":["awk","magic","notes","regex","sed"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mkayontour.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-01-13T11:33:46.000Z","updated_at":"2019-02-01T19:38:13.000Z","dependencies_parsed_at":"2024-05-17T08:48:34.897Z","dependency_job_id":null,"html_url":"https://github.com/mkayontour/regex_sed_awk_magix","commit_stats":null,"previous_names":["mkayontour/regex_sed_awk_magix"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mkayontour/regex_sed_awk_magix","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkayontour%2Fregex_sed_awk_magix","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkayontour%2Fregex_sed_awk_magix/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkayontour%2Fregex_sed_awk_magix/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkayontour%2Fregex_sed_awk_magix/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mkayontour","download_url":"https://codeload.github.com/mkayontour/regex_sed_awk_magix/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkayontour%2Fregex_sed_awk_magix/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31961348,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T00:39:45.007Z","status":"online","status_checked_at":"2026-04-18T02:00:07.018Z","response_time":103,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["awk","magic","notes","regex","sed"],"created_at":"2024-11-15T19:58:17.901Z","updated_at":"2026-04-18T08:01:48.787Z","avatar_url":"https://github.com/mkayontour.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n## AWK\n\n#### Multiline\nDo some multiline magic and bring those into one line.\n```\ncat multiline_file\n--\n  name ich\n  info langsam\n  platz 2\n\n--\n  name du\n  info schnell\n  platz 1\n```\n\n```\nawk '/--/{if (x)print x;x=\"\";next}{x=(!x)?$0:x\" \"$0;}END{print x;}' multiline_file\n```\nResult:\n```\nname ich   info langsam   platz 2\nname du   info schnell   platz 1\n```\n\n### gsub\n#### Whitespaces and Tabs\nSearch and replace with gsub in awk\nText with tabs or two whitespaces, will be replaced by `;`\n```\ncat gsub_white_tab\nhello this  is a  example\n```\nUse:\n```\nawk '{gsub(\"  |\\t+\",\";\");print }' gsub_white_tab\n```\nResult:\n```\nhello this;is a;example\n```\n\n#### File basename\n\nget only filename and cat the path\n```\necho \"/opt/icinga/test/check_icinga\" | awk '{gsub(/.*\\//,\"\");print}'\ncheck_icinga\n```\nNeeded this when working on some CSV stuff\n```\necho \"/opt/icinga/test/check_test;somethingother;morestuff\" | awk 'BEGIN{FS=\";\";OFS=FS}{base=$1;gsub(/.*\\//,\"\",base);print base}'\n```\nResult:\n```\ncheck_test\n```\n#### Remove fields from row\n```\nrow1;row2;row3;row4\n```\nUse:\n```\necho \"row1;row2;row3;row4\" | awk -F \";\" '{$2=$4=\"\"; print}'\n```\nResult:\n```\nrow1  row3\n```\n\nCan be done much easier if using cut\n```\necho \"row1;row2;row3;row4\" | cut -d \";\" -f-1,3\n```\nResult:\n```\nrow1;row3\n```\n#### Remove whitespace from end of line\n```\necho \"whitespace at endline \" |awk 'sub(/ *$/, \"\")'\n```\n\n## SED\n\n#### Whitespace and Tabs\nSearch for two or more whitespaces and make them one space\n```\ncat whitespaces_tabs\nHallo World\nThis  is Text  with   tabs and  spaces\n```\nUse:\n```\nsed -e 's/[[:space:]]\\{2,\\}/\\ /g' whitespaces_tabs\n```\nThe syntax with `[[:space:]]` is for POSIX compatibility.\n\nResult:\n```\nHallo World\nThis is Text with tabs and spaces\n```\n\n\n#### more\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkayontour%2Fregex_sed_awk_magix","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmkayontour%2Fregex_sed_awk_magix","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkayontour%2Fregex_sed_awk_magix/lists"}