{"id":31378,"date":"2023-01-21T02:20:20","date_gmt":"2023-01-20T20:50:20","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-grep-lines-that-contain-1-character-followed-by-another-character\/"},"modified":"2023-01-21T02:20:20","modified_gmt":"2023-01-20T20:50:20","slug":"solved-grep-lines-that-contain-1-character-followed-by-another-character","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-grep-lines-that-contain-1-character-followed-by-another-character\/","title":{"rendered":"[Solved] grep lines that contain 1 character followed by another character"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-48016083\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"48016083\" data-parentid=\"48015371\" data-score=\"-1\" data-position-on-page=\"3\" data-highest-scored=\"0\" data-question-has-accepted-highest-score=\"0\" itemprop=\"suggestedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>You can go for the following two solutions:<\/p>\n<pre><code>grep -ie 'b[^e]' input_file.txt\n<\/code><\/pre>\n<p>or <\/p>\n<pre><code>grep -ie 'b.' input_file.txt | grep -vi 'be'\n<\/code><\/pre>\n<p><strong>The first one does use regex:<\/strong> <\/p>\n<ul>\n<li><code>'b[^e]'<\/code> means <code>b followed by any symbol that is not e<\/code><\/li>\n<li><code>-i<\/code> is to ignore case, with this option lines containing <code>B<\/code> or <code>b<\/code> that are not directly followed by <code>e<\/code> or <code>E<\/code> will be accepted <\/li>\n<\/ul>\n<p><strong>The second solution calls grep twice:<\/strong> <\/p>\n<ul>\n<li>the first time you look for patterns that contains b only to select those lines<\/li>\n<li>the resulting lines are filtered by the second grep using <code>-v<\/code> to reject lines containing <code>be<\/code><\/li>\n<li>both grep are ignoring the case by using <code>-i<\/code><\/li>\n<li>\n<p>if <code>b<\/code> must <strong>absolutely<\/strong> be followed by another character then use <code>b.<\/code> (regex meaning <code>b<\/code> followed by any other char) otherwise if you want to also accept lines where <code>b<\/code> is not followed by any other character at all you can just use <code>b<\/code> in the first grep call instead of <code>b.<\/code>. <\/p>\n<pre><code>grep -ie 'b' input_file.txt | grep -vi 'be'\n<\/code><\/pre>\n<\/li>\n<\/ul>\n<p><strong>input:<\/strong><\/p>\n<pre><code>BEBE\nbebe\ntoto\nabc\nbobo\n<\/code><\/pre>\n<p><strong>result:<\/strong><\/p>\n<pre><code>abc\nbobo\n<\/code><\/pre>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">2<\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved grep lines that contain 1 character followed by another character <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] You can go for the following two solutions: grep -ie &#8216;b[^e]&#8217; input_file.txt or grep -ie &#8216;b.&#8217; input_file.txt | grep -vi &#8216;be&#8217; The first one does use regex: &#8216;b[^e]&#8217; means b followed by any symbol that is not e -i is to ignore case, with this option lines containing B or b that are not &#8230; <a title=\"[Solved] grep lines that contain 1 character followed by another character\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-grep-lines-that-contain-1-character-followed-by-another-character\/\" aria-label=\"More on [Solved] grep lines that contain 1 character followed by another character\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[1042,424,443],"class_list":["post-31378","post","type-post","status-publish","format-standard","hentry","category-solved","tag-bash","tag-linux","tag-unix"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>[Solved] grep lines that contain 1 character followed by another character - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-grep-lines-that-contain-1-character-followed-by-another-character\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] grep lines that contain 1 character followed by another character - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] You can go for the following two solutions: grep -ie &#039;b[^e]&#039; input_file.txt or grep -ie &#039;b.&#039; input_file.txt | grep -vi &#039;be&#039; The first one does use regex: &#039;b[^e]&#039; means b followed by any symbol that is not e -i is to ignore case, with this option lines containing B or b that are not ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-grep-lines-that-contain-1-character-followed-by-another-character\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2023-01-20T20:50:20+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-grep-lines-that-contain-1-character-followed-by-another-character\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-grep-lines-that-contain-1-character-followed-by-another-character\\\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/person\\\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] grep lines that contain 1 character followed by another character\",\"datePublished\":\"2023-01-20T20:50:20+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-grep-lines-that-contain-1-character-followed-by-another-character\\\/\"},\"wordCount\":149,\"publisher\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#organization\"},\"keywords\":[\"bash\",\"linux\",\"unix\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-grep-lines-that-contain-1-character-followed-by-another-character\\\/\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-grep-lines-that-contain-1-character-followed-by-another-character\\\/\",\"name\":\"[Solved] grep lines that contain 1 character followed by another character - JassWeb\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#website\"},\"datePublished\":\"2023-01-20T20:50:20+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-grep-lines-that-contain-1-character-followed-by-another-character\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-grep-lines-that-contain-1-character-followed-by-another-character\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-grep-lines-that-contain-1-character-followed-by-another-character\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] grep lines that contain 1 character followed by another character\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#website\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/jassweb.com\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/jass-website-logo-1.png\",\"contentUrl\":\"https:\\\/\\\/jassweb.com\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/person\\\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/wp-content\\\/litespeed\\\/avatar\\\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/wp-content\\\/litespeed\\\/avatar\\\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400\",\"contentUrl\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/wp-content\\\/litespeed\\\/avatar\\\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\\\/\\\/jassweb.com\"],\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/author\\\/jaspritsinghghumangmail-com\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] grep lines that contain 1 character followed by another character - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-grep-lines-that-contain-1-character-followed-by-another-character\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] grep lines that contain 1 character followed by another character - JassWeb","og_description":"[ad_1] You can go for the following two solutions: grep -ie 'b[^e]' input_file.txt or grep -ie 'b.' input_file.txt | grep -vi 'be' The first one does use regex: 'b[^e]' means b followed by any symbol that is not e -i is to ignore case, with this option lines containing B or b that are not ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-grep-lines-that-contain-1-character-followed-by-another-character\/","og_site_name":"JassWeb","article_published_time":"2023-01-20T20:50:20+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-grep-lines-that-contain-1-character-followed-by-another-character\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-grep-lines-that-contain-1-character-followed-by-another-character\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] grep lines that contain 1 character followed by another character","datePublished":"2023-01-20T20:50:20+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-grep-lines-that-contain-1-character-followed-by-another-character\/"},"wordCount":149,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["bash","linux","unix"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-grep-lines-that-contain-1-character-followed-by-another-character\/","url":"https:\/\/jassweb.com\/solved\/solved-grep-lines-that-contain-1-character-followed-by-another-character\/","name":"[Solved] grep lines that contain 1 character followed by another character - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2023-01-20T20:50:20+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-grep-lines-that-contain-1-character-followed-by-another-character\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-grep-lines-that-contain-1-character-followed-by-another-character\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-grep-lines-that-contain-1-character-followed-by-another-character\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] grep lines that contain 1 character followed by another character"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/31378","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=31378"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/31378\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=31378"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=31378"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=31378"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}