{"id":12065,"date":"2022-09-29T12:26:06","date_gmt":"2022-09-29T06:56:06","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-add-an-exclude-array-to-an-existing-awk-code\/"},"modified":"2022-09-29T12:26:06","modified_gmt":"2022-09-29T06:56:06","slug":"solved-add-an-exclude-array-to-an-existing-awk-code","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-add-an-exclude-array-to-an-existing-awk-code\/","title":{"rendered":"[Solved] Add an exclude array to an existing awk code"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-61324038\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"61324038\" data-parentid=\"61323065\" data-score=\"2\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" 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><strong><em>EDIT:<\/em><\/strong> OP told there could be words like <code>\"a\"<\/code> too so handle that case adding following now.<\/p>\n<pre><code>awk '\nBEGIN{\n  s1=\"\\\"\"\n  num=split(\"McCartney feat. vs. CD USA NYC\",array,\" \")\n  for(k=1;k&lt;=num;k++){\n     temp=tolower(array[k])\n     ignoreLetters[temp]=array[k]\n  }\n  num=split(\"a the to at in on with and but or\",array,\" \")\n  for(i=1;i&lt;=num;i++){\n    smallLetters[array[i]]=array[i]\n  }\n}\n\/TITLE\/{\n  for(i=2;i&lt;=NF;i++){\n    front=end=nothing=both=\"\"\n    if($i~\/^\"\/ &amp;&amp; $i!~\/\"$\/){\n      temp=tolower(substr($i,2))\n      front=1\n    }\n    else if($i ~ \/^\".*\"$\/){\n      temp=tolower(substr($i,2,length($i)-2))\n      both=1\n    }\n    else if($i ~\/\"$\/ &amp;&amp; $i!~\/^\"\/){\n      temp=tolower(substr($i,1,length($i)-1))\n      end=1\n    }\n    else{\n      temp=tolower($i)\n      nothing=1\n    }\n    if(temp in ignoreLetters){\n      if(front){\n         $i=s1 ignoreLetters[temp]\n      }\n      else if(end){\n         $i=ignoreLetters[temp] s1\n      }\n      else if(both){\n         $i=s1 ignoreLetters[temp] s1\n      }\n      else if(nothing){\n         $i=ignoreLetters[temp]\n      }\n    }\n    else if(temp in smallLetters){\n      if(front){\n         $i=s1 smallLetters[temp]\n      }\n      else if(end){\n         $i=smallLetters[temp] s1\n      }\n      else if(nothing){\n         $i=smallLetters[temp]\n      }\n      else if(both){\n         $i=s1 smallLetters[temp] s1\n      }\n    }\n    else{\n      if($i~\/^\\\"\/){\n        $i=substr($i,1,1) toupper(substr($i,2,1)) substr($i,3)\n      }\n      else{\n        $i=toupper(substr($i,1,1)) substr($i,2)\n      }\n    }\n  }\n}\n1\n'  Input_file\n<\/code><\/pre>\n<hr>\n<hr>\n<p>Could you please try following.<\/p>\n<pre><code>awk '\nBEGIN{\n  s1=\"\\\"\"\n  num=split(\"McCartney feat. vs. CD USA NYC\",array,\" \")\n  for(k=1;k&lt;=num;k++){\n     temp=tolower(array[k])\n     ignoreLetters[temp]=array[k]\n  }\n  num=split(\"a the to at in on with and but or\",array,\" \")\n  for(i=1;i&lt;=num;i++){\n    smallLetters[array[i]]=array[i]\n  }\n}\n\/TITLE\/{\n  for(i=2;i&lt;=NF;i++){\n    front=end=nothing=\"\"\n    if($i~\/^\"\/){\n      temp=tolower(substr($i,2))\n      front=1\n    }\n    else if($i ~\/\"$\/){\n      temp=tolower(substr($i,1,length($i)-1))\n      end=1\n    }\n    else{\n      temp=tolower($i)\n      nothing=1\n    }\n    if(temp in ignoreLetters){\n      if(front){\n         $i=s1 ignoreLetters[temp]\n      }\n      else if(end){\n         $i=ignoreLetters[temp] s1\n      }\n      else if(nothing){\n         $i=ignoreLetters[temp]\n      }\n    }\n    else if(tolower($i) in smallLetters){\n      $i=tolower(substr($i,1,1)) substr($i,2)\n    }\n    else{\n      if($i~\/^\\\"\/){\n        $i=substr($i,1,1) toupper(substr($i,2,1)) substr($i,3)\n      }\n      else{\n        $i=toupper(substr($i,1,1)) substr($i,2)\n      }\n    }\n  }\n}\n1\n'  Input_file\n<\/code><\/pre>\n<p>Output will be as follows:<\/p>\n<pre><code>FILE \"Two The Beatles Songs.wav\" WAVE\n  TRACK 01 AUDIO\nTITLE \"Dig a Pony, feat. Paul McCartney\"\n    PERFORMER \"The Beatles\"\n    INDEX 01 00:00:00\n  TRACK 02 AUDIO\nTITLE \"From Me to You\"\n    PERFORMER \"The Beatles\"\n    INDEX 01 03:58:02\n<\/code><\/pre>\n<p><strong><em>What does code take care of:<\/em><\/strong><\/p>\n<ul>\n<li>It takes care of making mentioned words into small letters.<\/li>\n<li>It takes care of making some letters as per their style, mentioned by OP in question.<\/li>\n<li>It takes of rest of fields which DO NOT fall in any of above category and makes their first letter as capital letter.<\/li>\n<li>Code also takes care of words starting with <code>\"<\/code> OR ending with <code>\"<\/code> too, it will first remove them to check if they are present into user mentioned array or not and later add them as per their position.<\/li>\n<\/ul>\n<\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">1<\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved Add an exclude array to an existing awk code <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] EDIT: OP told there could be words like &#8220;a&#8221; too so handle that case adding following now. awk &#8216; BEGIN{ s1=&#8221;\\&#8221;&#8221; num=split(&#8220;McCartney feat. vs. CD USA NYC&#8221;,array,&#8221; &#8220;) for(k=1;k&lt;=num;k++){ temp=tolower(array[k]) ignoreLetters[temp]=array[k] } num=split(&#8220;a the to at in on with and but or&#8221;,array,&#8221; &#8220;) for(i=1;i&lt;=num;i++){ smallLetters[array[i]]=array[i] } } \/TITLE\/{ for(i=2;i&lt;=NF;i++){ front=end=nothing=both=&#8221;&#8221; if($i~\/^&#8221;\/ &amp;&amp; $i!~\/&#8221;$\/){ temp=tolower(substr($i,2)) &#8230; <a title=\"[Solved] Add an exclude array to an existing awk code\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-add-an-exclude-array-to-an-existing-awk-code\/\" aria-label=\"More on [Solved] Add an exclude array to an existing awk code\">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":[445],"class_list":["post-12065","post","type-post","status-publish","format-standard","hentry","category-solved","tag-awk"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>[Solved] Add an exclude array to an existing awk code - 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-add-an-exclude-array-to-an-existing-awk-code\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] Add an exclude array to an existing awk code - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] EDIT: OP told there could be words like &quot;a&quot; too so handle that case adding following now. awk &#039; BEGIN{ s1=&quot;&quot;&quot; num=split(&quot;McCartney feat. vs. CD USA NYC&quot;,array,&quot; &quot;) for(k=1;k&lt;=num;k++){ temp=tolower(array[k]) ignoreLetters[temp]=array[k] } num=split(&quot;a the to at in on with and but or&quot;,array,&quot; &quot;) for(i=1;i&lt;=num;i++){ smallLetters[array[i]]=array[i] } } \/TITLE\/{ for(i=2;i&lt;=NF;i++){ front=end=nothing=both=&quot;&quot; if($i~\/^&quot;\/ &amp;&amp; $i!~\/&quot;$\/){ temp=tolower(substr($i,2)) ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-add-an-exclude-array-to-an-existing-awk-code\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-09-29T06:56:06+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=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-add-an-exclude-array-to-an-existing-awk-code\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-add-an-exclude-array-to-an-existing-awk-code\\\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/person\\\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] Add an exclude array to an existing awk code\",\"datePublished\":\"2022-09-29T06:56:06+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-add-an-exclude-array-to-an-existing-awk-code\\\/\"},\"wordCount\":140,\"publisher\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#organization\"},\"keywords\":[\"awk\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-add-an-exclude-array-to-an-existing-awk-code\\\/\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-add-an-exclude-array-to-an-existing-awk-code\\\/\",\"name\":\"[Solved] Add an exclude array to an existing awk code - JassWeb\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#website\"},\"datePublished\":\"2022-09-29T06:56:06+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-add-an-exclude-array-to-an-existing-awk-code\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-add-an-exclude-array-to-an-existing-awk-code\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-add-an-exclude-array-to-an-existing-awk-code\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] Add an exclude array to an existing awk code\"}]},{\"@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] Add an exclude array to an existing awk code - 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-add-an-exclude-array-to-an-existing-awk-code\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] Add an exclude array to an existing awk code - JassWeb","og_description":"[ad_1] EDIT: OP told there could be words like \"a\" too so handle that case adding following now. awk ' BEGIN{ s1=\"\"\" num=split(\"McCartney feat. vs. CD USA NYC\",array,\" \") for(k=1;k&lt;=num;k++){ temp=tolower(array[k]) ignoreLetters[temp]=array[k] } num=split(\"a the to at in on with and but or\",array,\" \") for(i=1;i&lt;=num;i++){ smallLetters[array[i]]=array[i] } } \/TITLE\/{ for(i=2;i&lt;=NF;i++){ front=end=nothing=both=\"\" if($i~\/^\"\/ &amp;&amp; $i!~\/\"$\/){ temp=tolower(substr($i,2)) ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-add-an-exclude-array-to-an-existing-awk-code\/","og_site_name":"JassWeb","article_published_time":"2022-09-29T06:56:06+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-add-an-exclude-array-to-an-existing-awk-code\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-add-an-exclude-array-to-an-existing-awk-code\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] Add an exclude array to an existing awk code","datePublished":"2022-09-29T06:56:06+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-add-an-exclude-array-to-an-existing-awk-code\/"},"wordCount":140,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["awk"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-add-an-exclude-array-to-an-existing-awk-code\/","url":"https:\/\/jassweb.com\/solved\/solved-add-an-exclude-array-to-an-existing-awk-code\/","name":"[Solved] Add an exclude array to an existing awk code - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-09-29T06:56:06+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-add-an-exclude-array-to-an-existing-awk-code\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-add-an-exclude-array-to-an-existing-awk-code\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-add-an-exclude-array-to-an-existing-awk-code\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] Add an exclude array to an existing awk code"}]},{"@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\/12065","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=12065"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/12065\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=12065"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=12065"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=12065"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}