{"id":4629,"date":"2025-06-23T06:38:00","date_gmt":"2025-06-22T21:38:00","guid":{"rendered":"https:\/\/matoken.org\/blog\/?p=4629"},"modified":"2025-06-23T00:42:05","modified_gmt":"2025-06-22T15:42:05","slug":"show-all-after-match-line-with-ugrep","status":"publish","type":"post","link":"https:\/\/matoken.org\/blog\/2025\/06\/23\/show-all-after-match-line-with-ugrep\/","title":{"rendered":"ugrep\u3067\u30de\u30c3\u30c1\u884c\u4ee5\u964d\u5168\u3066\u8868\u793a"},"content":{"rendered":"<div id=\"preamble\">\n<div class=\"sectionbody\">\n<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"48\" height=\"48\" viewBox=\"0 0 24 24\"><path fill=\"currentColor\" d=\"M15 3H5c-1.11 0-2 .89-2 2v5.82A6.4 6.4 0 0 1 5 9.5V5h7v5.82c.03.03.07.05.1.08c.34.34.63.71.87 1.1H19v7h-6.03c-.24.39-.53.76-.87 1.1c-.36.35-.75.64-1.16.9H19c1.11 0 2-.89 2-2V9zm-1 7V4.5l5.5 5.5zm-6.5 1C5 11 3 13 3 15.5c0 .88.25 1.71.69 2.4L.61 21L2 22.39l3.12-3.07c.69.43 1.51.68 2.38.68c2.5 0 4.5-2 4.5-4.5S10 11 7.5 11m0 7a2.5 2.5 0 0 1 0-5a2.5 2.5 0 0 1 0 5\"\/><\/svg><!-- mdi:note-search-outline --><\/p>\n<div class=\"paragraph\">\n<p>grep\u30b3\u30de\u30f3\u30c9\u306b\u30de\u30c3\u30c1\u3057\u305f\u90e8\u5206\u304b\u3089\u6307\u5b9a\u884c\u3092\u8868\u793a\u3059\u308b\u6a5f\u80fd\u304c\u3042\u308a\u307e\u3059\uff0e<br \/>\n\u4f8b\u3048\u3070\u4ee5\u4e0b\u306e\u4f8b\u3067\u306f\u30de\u30c3\u30c1\u3057\u305f\u90e8\u5206\u304b\u3089\u5f8c\u308d11\u884c\u3092\u8868\u793a\uff0e<\/p>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre>$ man grep | grep 'Context Line Control' -A 11\n   Context Line Control\n       -A NUM, --after-context=NUM\n              Print NUM lines of trailing context after matching lines.  Places a line containing a group separator (--) between contiguous groups of matches.  With the -o or --only-matching option, this has no effect  and  a  warning  is\n              given.\n\n       -B NUM, --before-context=NUM\n              Print  NUM  lines  of  leading context before matching lines.  Places a line containing a group separator (--) between contiguous groups of matches.  With the -o or --only-matching option, this has no effect and a warning is\n              given.\n\n       -C NUM, -NUM, --context=NUM\n              Print NUM lines of output context.  Places a line containing a group separator (--) between contiguous groups of matches.  With the -o or --only-matching option, this has no effect and a warning is given.<\/pre>\n<\/div>\n<\/div>\n<div class=\"paragraph\">\n<p>\u30de\u30c3\u30c1\u3057\u305f\u90e8\u5206\u4ee5\u964d\u5168\u3066\u3092\u8868\u793a\u3057\u305f\u3044\u3053\u3068\u304c\u3042\u308a\u307e\u3059\uff0e\u884c\u6570\u3092\u78ba\u8a8d\u3059\u308b\u306e\u304c\u9762\u5012\u3060\u3063\u305f\u308a\u3059\u308b\u306e\u3067 <code>-A 999<\/code> \u3068\u304b\u3084\u308a\u304c\u3061\u3067\u3059\uff0e<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>ugrep \u306b\u6700\u5f8c\u307e\u3067\u8868\u793a\u3067\u304d\u308b\u30aa\u30d7\u30b7\u30e7\u30f3\u304c\u3042\u308b\u306e\u306b\u6c17\u3065\u3044\u305f\u306e\u3067\u30e1\u30e2\u3057\u3066\u304a\u304d\u307e\u3059\uff0e<\/p>\n<\/div>\n<p><!--more--><\/p>\n<div class=\"ulist\">\n<ul>\n<li>\n<p><a href=\"https:\/\/www.gnu.org\/software\/grep\/\">Grep &#8211; GNU Project &#8211; Free Software Foundation<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/Genivia\/ugrep\/wiki\">Home \u00b7 Genivia\/ugrep Wiki<\/a><\/p>\n<div class=\"ulist\">\n<ul>\n<li>\n<p><a href=\"https:\/\/ugrep.com\/\">The ugrep file pattern searcher<\/a><\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/li>\n<\/ul>\n<\/div>\n<div class=\"paragraph\">\n<p>Debian\u3067\u306fGNU grep\u306f <code>grep<\/code> \u30d1\u30c3\u30b1\u30fc\u30b8\u3067\uff0cugrep \u306f <code>ugrep<\/code> \u30d1\u30c3\u30b1\u30fc\u30b8\u3067\u63d0\u4f9b\u3055\u308c\u3066\u3044\u307e\u3059\uff0e<\/p>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"title\">\u5c0e\u5165<\/div>\n<div class=\"content\">\n<pre>$ sudo apt install grep\n$ sudo apt install ugrep<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"sect1\">\n<h2 id=\"_gnu_grep_\u3092\u8a66\u3059\">GNU grep \u3092\u8a66\u3059<\/h2>\n<div class=\"sectionbody\">\n<div class=\"listingblock\">\n<div class=\"title\">\u9069\u5f53\u306a\u30c6\u30ad\u30b9\u30c8<\/div>\n<div class=\"content\">\n<pre>$ awk -F: '{if ($3 &lt; 1000) {print $1 }}' \/etc\/passwd | head\nroot\ndaemon\nbin\nsys\nsync\ngames\nman\nlp\nmail\nnews<\/pre>\n<\/div>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"title\"><code>GNU grep<\/code> \u3067 <code>man<\/code> \u306e\u5f8c2\u884c\u3092\u8868\u793a<\/div>\n<div class=\"content\">\n<pre>$ awk -F: '{if ($3 &lt; 1000) {print $1 }}' \/etc\/passwd | head | grep -A2 -- ^man$\nman\nlp\nmail<\/pre>\n<\/div>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"title\"><code>GNU grep<\/code> \u3067 <code>man<\/code> \u306e\u524d2\u884c\u3092\u8868\u793a<\/div>\n<div class=\"content\">\n<pre>$ awk -F: '{if ($3 &lt; 1000) {print $1 }}' \/etc\/passwd | head | grep -B2 -- ^man$\nsync\ngames\nman<\/pre>\n<\/div>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"title\"><code>GNU grep<\/code> \u3067 <code>man<\/code> \u306e\u524d\u5f8c\u305d\u308c\u305e\u308c2\u884c\u3092\u8868\u793a<\/div>\n<div class=\"content\">\n<pre>$ awk -F: '{if ($3 &lt; 1000) {print $1 }}' \/etc\/passwd | head | grep -C2 -- ^man$\nsync\ngames\nman\nlp\nmail<\/pre>\n<\/div>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"title\"><code>GNU grep<\/code> \u3067 <code>man<\/code> \u306e\u524d1\u884c\u5f8c2\u884c\u3092\u8868\u793a<\/div>\n<div class=\"content\">\n<pre>$ awk -F: '{if ($3 &lt; 1000) {print $1 }}' \/etc\/passwd | head | grep -B1 -A2 -- ^man$\ngames\nman\nlp\nmail<\/pre>\n<\/div>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"title\"><code>GNU grep<\/code> \u3067 <code>man<\/code> \u306e\u5f8c99\u884c\u3092\u8868\u793a(\u5b9f\u969b\u306f\u305d\u3093\u306a\u306b\u884c\u6570\u304c\u306a\u3044\u306e\u3067\u6700\u5f8c\u307e\u3067\u8868\u793a)<\/div>\n<div class=\"content\">\n<pre>$ awk -F: '{if ($3 &lt; 1000) {print $1 }}' \/etc\/passwd | head | grep -A99 -- ^man$\nman\nlp\nmail\nnews<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"sect1\">\n<h2 id=\"_ugrep_\u3092\u8a66\u3059\">ugrep \u3092\u8a66\u3059<\/h2>\n<div class=\"sectionbody\">\n<div class=\"paragraph\">\n<p>ugrep \u3082GNU grep\u3068\u540c\u3058\u3088\u3046\u306b <code>-A\/-B\/-C<\/code> \u304c\u4f7f\u3048\u307e\u3059\uff0e\u305d\u3057\u3066 <code>-A<\/code> \u5229\u7528\u6642\u306b\u306f\u884c\u6570\u306b <code>-1<\/code> \u304c\u6307\u5b9a\u53ef\u80fd\u3067\u3053\u308c\u3067\u30de\u30c3\u30c1\u90e8\u5206\u304b\u3089\u6700\u5f8c\u307e\u3067\u8868\u793a\u3067\u304d\u307e\u3059\uff0e<\/p>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"title\"><code>grep<\/code> \u3067 <code>man<\/code> \u306e\u5f8c\u3059\u3079\u3066\u3092\u8868\u793a<\/div>\n<div class=\"content\">\n<pre>$ awk -F: '{if ($3 &lt; 1000) {print $1 }}' \/etc\/passwd | head | ugrep -A-1 -- ^man$\nman\nlp\nmail\nnews<\/pre>\n<\/div>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"title\"><code>-B<\/code> \u306b\u306f\u4f7f\u3048\u306a\u3044<\/div>\n<div class=\"content\">\n<pre>$ awk -F: '{if ($3 &lt; 1000) {print $1 }}' \/etc\/passwd | head | ugrep -B-1 -- ^man$\nugrep: warning: exception while searching (standard input): Inappropriate ioctl for device<\/pre>\n<\/div>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"title\">tac\u3067\u9006\u9806\u306b\u3057\u3066 <code>-1<\/code> \u3067\u5207\u308a\u53d6\u3063\u305f\u3068\u518d\u5ea6tac\u3067\u9006\u9806\u306b<\/div>\n<div class=\"content\">\n<pre>$ awk -F: '{if ($3 &lt; 1000) {print $1 }}' \/etc\/passwd | head | tac | ugrep -A-1 -- ^man$ | tac\nroot\ndaemon\nbin\nsys\nsync\ngames\nman<\/pre>\n<\/div>\n<\/div>\n<div class=\"paragraph\">\n<p>ugrep\u306f\u4ed6\u306b\u3082\u5bfe\u8a71\u578b\u554f\u3044\u5408\u308f\u305b\u306e\u6a5f\u80fd(-Q)\u3084\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u4f5c\u6210\u3057\u3066\u691c\u7d22\u3092\u9ad8\u901f\u5316(-indexer)\u3059\u308b\u6a5f\u80fd\u306a\u3069\u69d8\u3005\u306a\u6a5f\u80fd\u304c\u542b\u307e\u308c\u3066\u3044\u307e\u3059\uff0e<br \/>\n\u3082\u3063\u3068\u4f7f\u3044\u3053\u306a\u3057\u3066\u3044\u304d\u305f\u3044\u3068\u3053\u308d\u3067\u3059\uff0e<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"sect1\">\n<h2 id=\"_\u5225\u89e3_sed_awk_perl\">\u5225\u89e3: sed, awk, perl<\/h2>\n<div class=\"sectionbody\">\n<div class=\"listingblock\">\n<div class=\"title\">sed<\/div>\n<div class=\"content\">\n<pre>$ awk -F: '{if ($3 &lt; 1000) {print $1 }}' \/etc\/passwd | head | sed -n '\/^man$\/,$p'\nman\nlp\nmail\nnews<\/pre>\n<\/div>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"title\">awk<\/div>\n<div class=\"content\">\n<pre>$ awk -F: '{if ($3 &lt; 1000) {print $1 }}' \/etc\/passwd | head | awk '\/^man$\/',0\nman\nlp\nmail\nnews<\/pre>\n<\/div>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"title\">perl<\/div>\n<div class=\"content\">\n<pre>$ awk -F: '{if ($3 &lt; 1000) {print $1 }}' \/etc\/passwd | head | perl -ne \"print if \/^man$\/ .. eof;\"\nman\nlp\nmail\nnews<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"sect1\">\n<h2 id=\"_\u74b0\u5883\">\u74b0\u5883<\/h2>\n<div class=\"sectionbody\">\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre>$ dpkg-query -W grep ugrep sed gawk perl\ngawk    1:5.3.2-1\ngrep    3.11-4\nperl    5.40.1-3\nsed     4.9-2\nugrep   7.4.2+dfsg-1\n$ lsb_release -dr\nDescription:    Debian GNU\/Linux 13 (trixie)\nRelease:        13\n$ arch\nx86_64<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>grep\u30b3\u30de\u30f3\u30c9\u306b\u30de\u30c3\u30c1\u3057\u305f\u90e8\u5206\u304b\u3089\u6307\u5b9a\u884c\u3092\u8868\u793a\u3059\u308b\u6a5f\u80fd\u304c\u3042\u308a\u307e\u3059\uff0e \u4f8b\u3048\u3070\u4ee5\u4e0b\u306e\u4f8b\u3067\u306f\u30de\u30c3\u30c1\u3057\u305f\u90e8\u5206\u304b\u3089\u5f8c\u308d11\u884c\u3092\u8868\u793a\uff0e $ man grep | grep &#8216;Context Line Control&#8217; -A 11  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"webmentions_disabled_pings":false,"webmentions_disabled":false,"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":4,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"federated","footnotes":""},"categories":[7,6,199],"tags":[1215,1216],"class_list":["post-4629","post","type-post","status-publish","format-standard","hentry","category-debian-linux","category-linux","category-sid","tag-grep","tag-ugrep"],"_links":{"self":[{"href":"https:\/\/matoken.org\/blog\/wp-json\/wp\/v2\/posts\/4629","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/matoken.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/matoken.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/matoken.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/matoken.org\/blog\/wp-json\/wp\/v2\/comments?post=4629"}],"version-history":[{"count":1,"href":"https:\/\/matoken.org\/blog\/wp-json\/wp\/v2\/posts\/4629\/revisions"}],"predecessor-version":[{"id":4630,"href":"https:\/\/matoken.org\/blog\/wp-json\/wp\/v2\/posts\/4629\/revisions\/4630"}],"wp:attachment":[{"href":"https:\/\/matoken.org\/blog\/wp-json\/wp\/v2\/media?parent=4629"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/matoken.org\/blog\/wp-json\/wp\/v2\/categories?post=4629"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/matoken.org\/blog\/wp-json\/wp\/v2\/tags?post=4629"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}